home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / AvantBrowser / asetup.exe / _data / webkit / resources.pak / Unnamed File 000115.unknown < prev    next >
Text File  |  2013-04-03  |  96KB  |  3,228 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. WebInspector.RequestView = function(request)
  8. {
  9. WebInspector.View.call(this);
  10. this.registerRequiredCSS("resourceView.css");
  11.  
  12. this.element.addStyleClass("resource-view");
  13. this.request = request;
  14. }
  15.  
  16. WebInspector.RequestView.prototype = {
  17. hasContent: function()
  18. {
  19. return false;
  20. },
  21.  
  22. __proto__: WebInspector.View.prototype
  23. }
  24.  
  25.  
  26. WebInspector.RequestView.hasTextContent = function(request)
  27. {
  28. if (request.type.isTextType())
  29. return true; 
  30. if (request.type === WebInspector.resourceTypes.Other || request.hasErrorStatusCode())
  31. return request.content && !request.contentEncoded;
  32. return false;
  33. }
  34.  
  35.  
  36. WebInspector.RequestView.nonSourceViewForRequest = function(request)
  37. {
  38. switch (request.type) {
  39. case WebInspector.resourceTypes.Image:
  40. return new WebInspector.ImageView(request);
  41. case WebInspector.resourceTypes.Font:
  42. return new WebInspector.FontView(request);
  43. default:
  44. return new WebInspector.RequestView(request);
  45. }
  46. }
  47. ;
  48.  
  49.  
  50.  
  51. WebInspector.NetworkItemView = function(request)
  52. {
  53. WebInspector.TabbedPane.call(this);
  54. this.element.addStyleClass("network-item-view");
  55.  
  56. var headersView = new WebInspector.RequestHeadersView(request);
  57. this.appendTab("headers", WebInspector.UIString("Headers"), headersView);
  58.  
  59. this.addEventListener(WebInspector.TabbedPane.EventTypes.TabSelected, this._tabSelected, this);
  60.  
  61. if (request.frames().length > 0) {
  62. var frameView = new WebInspector.ResourceWebSocketFrameView(request);
  63. this.appendTab("webSocketFrames", WebInspector.UIString("Frames"), frameView);
  64. return;
  65. }
  66.  
  67. var responseView = new WebInspector.RequestResponseView(request);
  68. var previewView = new WebInspector.RequestPreviewView(request, responseView);
  69. this.appendTab("preview", WebInspector.UIString("Preview"), previewView);
  70. this.appendTab("response", WebInspector.UIString("Response"), responseView);
  71.  
  72. if (request.requestCookies || request.responseCookies) {
  73. this._cookiesView = new WebInspector.RequestCookiesView(request);
  74. this.appendTab("cookies", WebInspector.UIString("Cookies"), this._cookiesView);
  75. }
  76.  
  77. if (request.timing) {
  78. var timingView = new WebInspector.RequestTimingView(request);
  79. this.appendTab("timing", WebInspector.UIString("Timing"), timingView);
  80. }
  81. this._request = request;
  82. }
  83.  
  84. WebInspector.NetworkItemView.prototype = {
  85. wasShown: function()
  86. {
  87. WebInspector.TabbedPane.prototype.wasShown.call(this);
  88. this._selectTab();
  89. },
  90.  
  91.  
  92. _selectTab: function(tabId)
  93. {
  94. if (!tabId)
  95. tabId = WebInspector.settings.resourceViewTab.get();
  96.  
  97. if (!this.selectTab(tabId)) {
  98. this._isInFallbackSelection = true;
  99. this.selectTab("headers");
  100. delete this._isInFallbackSelection;
  101. }
  102. },
  103.  
  104. _tabSelected: function(event)
  105. {
  106. if (!event.data.isUserGesture)
  107. return;
  108.  
  109. WebInspector.settings.resourceViewTab.set(event.data.tabId);
  110.  
  111. WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMetrics.UserAction, {
  112. action: WebInspector.UserMetrics.UserActionNames.NetworkRequestTabSelected,
  113. tab: event.data.tabId,
  114. url: this._request.url
  115. });
  116. },
  117.  
  118.  
  119. request: function()
  120. {
  121. return this._request;
  122. },
  123.  
  124. __proto__: WebInspector.TabbedPane.prototype
  125. }
  126.  
  127.  
  128. WebInspector.RequestContentView = function(request)
  129. {
  130. WebInspector.RequestView.call(this, request);
  131. }
  132.  
  133. WebInspector.RequestContentView.prototype = {
  134. hasContent: function()
  135. {
  136. return true;
  137. },
  138.  
  139. get innerView()
  140. {
  141. return this._innerView;
  142. },
  143.  
  144. set innerView(innerView)
  145. {
  146. this._innerView = innerView;
  147. },
  148.  
  149. wasShown: function()
  150. {
  151. this._ensureInnerViewShown();
  152. },
  153.  
  154. _ensureInnerViewShown: function()
  155. {
  156. if (this._innerViewShowRequested)
  157. return;
  158. this._innerViewShowRequested = true;
  159.  
  160.  
  161. function callback(content, contentEncoded, mimeType)
  162. {
  163. this._innerViewShowRequested = false;
  164. this.contentLoaded();
  165. }
  166.  
  167. this.request.requestContent(callback.bind(this));
  168. },
  169.  
  170. contentLoaded: function()
  171. {
  172.  
  173. },
  174.  
  175. canHighlightLine: function()
  176. {
  177. return this._innerView && this._innerView.canHighlightLine();
  178. },
  179.  
  180. highlightLine: function(line)
  181. {
  182. if (this.canHighlightLine())
  183. this._innerView.highlightLine(line);
  184. },
  185.  
  186. __proto__: WebInspector.RequestView.prototype
  187. }
  188. ;
  189.  
  190.  
  191.  
  192. WebInspector.RequestCookiesView = function(request)
  193. {
  194. WebInspector.View.call(this);
  195. this.element.addStyleClass("resource-cookies-view");
  196.  
  197. this._request = request;
  198.  
  199. request.addEventListener(WebInspector.NetworkRequest.Events.RequestHeadersChanged, this._refreshCookies, this);
  200. request.addEventListener(WebInspector.NetworkRequest.Events.ResponseHeadersChanged, this._refreshCookies, this);
  201. }
  202.  
  203. WebInspector.RequestCookiesView.prototype = {
  204. wasShown: function()
  205. {
  206. if (!this._gotCookies) {
  207. if (!this._emptyView) {
  208. this._emptyView = new WebInspector.EmptyView(WebInspector.UIString("This request has no cookies."));
  209. this._emptyView.show(this.element);
  210. }
  211. return;
  212. }
  213.  
  214. if (!this._cookiesTable)
  215. this._buildCookiesTable();
  216. },
  217.  
  218. get _gotCookies()
  219. {
  220. return (this._request.requestCookies && this._request.requestCookies.length) || (this._request.responseCookies && this._request.responseCookies.length);
  221. },
  222.  
  223. _buildCookiesTable: function()
  224. {
  225. this.detachChildViews();
  226.  
  227. this._cookiesTable = new WebInspector.CookiesTable(true);
  228. this._cookiesTable.addCookiesFolder(WebInspector.UIString("Request Cookies"), this._request.requestCookies);
  229. this._cookiesTable.addCookiesFolder(WebInspector.UIString("Response Cookies"), this._request.responseCookies);
  230. this._cookiesTable.show(this.element);
  231. },
  232.  
  233. _refreshCookies: function()
  234. {
  235. delete this._cookiesTable;
  236. if (!this._gotCookies || !this.isShowing())
  237. return;
  238. this._buildCookiesTable();
  239. this._cookiesTable.updateWidths();
  240. },
  241.  
  242. __proto__: WebInspector.View.prototype
  243. }
  244. ;
  245.  
  246.  
  247.  
  248. WebInspector.RequestHeadersView = function(request)
  249. {
  250. WebInspector.View.call(this);
  251. this.registerRequiredCSS("resourceView.css");
  252. this.element.addStyleClass("resource-headers-view");
  253.  
  254. this._request = request;
  255.  
  256. this._headersListElement = document.createElement("ol");
  257. this._headersListElement.className = "outline-disclosure";
  258. this.element.appendChild(this._headersListElement);
  259.  
  260. this._headersTreeOutline = new TreeOutline(this._headersListElement);
  261. this._headersTreeOutline.expandTreeElementsWhenArrowing = true;
  262.  
  263. this._urlTreeElement = new TreeElement("", null, false);
  264. this._urlTreeElement.selectable = false;
  265. this._headersTreeOutline.appendChild(this._urlTreeElement);
  266.  
  267. this._requestMethodTreeElement = new TreeElement("", null, false);
  268. this._requestMethodTreeElement.selectable = false;
  269. this._headersTreeOutline.appendChild(this._requestMethodTreeElement);
  270.  
  271. this._statusCodeTreeElement = new TreeElement("", null, false);
  272. this._statusCodeTreeElement.selectable = false;
  273. this._headersTreeOutline.appendChild(this._statusCodeTreeElement);
  274.  
  275. this._requestHeadersTreeElement = new TreeElement("", null, true);
  276. this._requestHeadersTreeElement.expanded = true;
  277. this._requestHeadersTreeElement.selectable = false;
  278. this._headersTreeOutline.appendChild(this._requestHeadersTreeElement);
  279.  
  280. this._decodeRequestParameters = true;
  281.  
  282. this._showRequestHeadersText = false;
  283. this._showResponseHeadersText = false;
  284.  
  285. this._queryStringTreeElement = new TreeElement("", null, true);
  286. this._queryStringTreeElement.expanded = true;
  287. this._queryStringTreeElement.selectable = false;
  288. this._queryStringTreeElement.hidden = true;
  289. this._headersTreeOutline.appendChild(this._queryStringTreeElement);
  290.  
  291. this._urlFragmentTreeElement = new TreeElement("", null, true);
  292. this._urlFragmentTreeElement.expanded = true;
  293. this._urlFragmentTreeElement.selectable = false;
  294. this._urlFragmentTreeElement.hidden = true;
  295. this._headersTreeOutline.appendChild(this._urlFragmentTreeElement);
  296.  
  297. this._formDataTreeElement = new TreeElement("", null, true);
  298. this._formDataTreeElement.expanded = true;
  299. this._formDataTreeElement.selectable = false;
  300. this._formDataTreeElement.hidden = true;
  301. this._headersTreeOutline.appendChild(this._formDataTreeElement);
  302.  
  303. this._requestPayloadTreeElement = new TreeElement(WebInspector.UIString("Request Payload"), null, true);
  304. this._requestPayloadTreeElement.expanded = true;
  305. this._requestPayloadTreeElement.selectable = false;
  306. this._requestPayloadTreeElement.hidden = true;
  307. this._headersTreeOutline.appendChild(this._requestPayloadTreeElement);
  308.  
  309. this._responseHeadersTreeElement = new TreeElement("", null, true);
  310. this._responseHeadersTreeElement.expanded = true;
  311. this._responseHeadersTreeElement.selectable = false;
  312. this._headersTreeOutline.appendChild(this._responseHeadersTreeElement);
  313.  
  314. request.addEventListener(WebInspector.NetworkRequest.Events.RequestHeadersChanged, this._refreshRequestHeaders, this);
  315. request.addEventListener(WebInspector.NetworkRequest.Events.ResponseHeadersChanged, this._refreshResponseHeaders, this);
  316. request.addEventListener(WebInspector.NetworkRequest.Events.FinishedLoading, this._refreshHTTPInformation, this);
  317.  
  318. this._refreshURL();
  319. this._refreshQueryString();
  320. this._refreshUrlFragment();
  321. this._refreshRequestHeaders();
  322. this._refreshResponseHeaders();
  323. this._refreshHTTPInformation();
  324. }
  325.  
  326. WebInspector.RequestHeadersView.prototype = {
  327.  
  328. _formatHeader: function(name, value)
  329. {
  330. var fragment = document.createDocumentFragment();
  331. fragment.createChild("div", "header-name").textContent = name + ":";
  332. fragment.createChild("div", "header-value source-code").textContent = value;
  333.  
  334. return fragment;
  335. },
  336.  
  337.  
  338. _formatParameter: function(value, className, decodeParameters)
  339. {
  340. var errorDecoding = false;
  341.  
  342. if (decodeParameters) {
  343. value = value.replace(/\+/g, " ");
  344. if (value.indexOf("%") >= 0) {
  345. try {
  346. value = decodeURIComponent(value);
  347. } catch(e) {
  348. errorDecoding = true;
  349. }
  350. }
  351. }
  352. var div = document.createElement("div");
  353. div.className = className;
  354. if (errorDecoding)
  355. div.createChild("span", "error-message").textContent = WebInspector.UIString("(unable to decode value)");
  356. else
  357. div.textContent = value;
  358. return div;
  359. },
  360.  
  361. _refreshURL: function()
  362. {
  363. this._urlTreeElement.title = this._formatHeader(WebInspector.UIString("Request URL"), this._request.url);
  364. },
  365.  
  366. _refreshQueryString: function()
  367. {
  368. var queryString = this._request.queryString();
  369. var queryParameters = this._request.queryParameters;
  370. this._queryStringTreeElement.hidden = !queryParameters;
  371. if (queryParameters)
  372. this._refreshParams(WebInspector.UIString("Query String Parameters"), queryParameters, queryString, this._queryStringTreeElement);
  373. },
  374.  
  375. _refreshUrlFragment: function()
  376. {
  377. var urlFragment = this._request.parsedURL.fragment;
  378. this._urlFragmentTreeElement.hidden = !urlFragment;
  379.  
  380. if (!urlFragment)
  381. return;
  382.  
  383. var sectionTitle = WebInspector.UIString("URL fragment");
  384.  
  385. this._urlFragmentTreeElement.removeChildren();
  386. this._urlFragmentTreeElement.listItemElement.removeChildren();
  387. this._urlFragmentTreeElement.listItemElement.appendChild(document.createTextNode(sectionTitle));
  388.  
  389. var fragmentTreeElement = new TreeElement(null, null, false);
  390. fragmentTreeElement.title = this._formatHeader("#", urlFragment);
  391. fragmentTreeElement.selectable = false;
  392. this._urlFragmentTreeElement.appendChild(fragmentTreeElement);
  393. },
  394.  
  395. _refreshFormData: function()
  396. {
  397. this._formDataTreeElement.hidden = true;
  398. this._requestPayloadTreeElement.hidden = true;
  399.  
  400. var formData = this._request.requestFormData;
  401. if (!formData)
  402. return;
  403.  
  404. var formParameters = this._request.formParameters;
  405. if (formParameters) {
  406. this._formDataTreeElement.hidden = false;
  407. this._refreshParams(WebInspector.UIString("Form Data"), formParameters, formData, this._formDataTreeElement);
  408. } else {
  409. this._requestPayloadTreeElement.hidden = false;
  410. this._populateTreeElementWithSourceText(this._requestPayloadTreeElement, formData)
  411. }
  412. },
  413.  
  414. _populateTreeElementWithSourceText: function(treeElement, sourceText)
  415. {
  416. treeElement.removeChildren();
  417.  
  418. var sourceTreeElement = new TreeElement(null, null, false);
  419. sourceTreeElement.selectable = false;
  420. treeElement.appendChild(sourceTreeElement);
  421.  
  422. var sourceTextElement = document.createElement("span");
  423. sourceTextElement.addStyleClass("header-value");
  424. sourceTextElement.addStyleClass("source-code");
  425. sourceTextElement.textContent = String(sourceText).trim();
  426. sourceTreeElement.listItemElement.appendChild(sourceTextElement);
  427. },
  428.  
  429. _refreshParams: function(title, params, sourceText, paramsTreeElement)
  430. {
  431. paramsTreeElement.removeChildren();
  432.  
  433. paramsTreeElement.listItemElement.removeChildren();
  434. paramsTreeElement.listItemElement.appendChild(document.createTextNode(title));
  435.  
  436. var headerCount = document.createElement("span");
  437. headerCount.addStyleClass("header-count");
  438. headerCount.textContent = WebInspector.UIString(" (%d)", params.length);
  439. paramsTreeElement.listItemElement.appendChild(headerCount);
  440.  
  441. function toggleViewSource()
  442. {
  443. paramsTreeElement._viewSource = !paramsTreeElement._viewSource;
  444. this._refreshParams(title, params, sourceText, paramsTreeElement);
  445. }
  446.  
  447. var viewSourceToggleTitle = paramsTreeElement._viewSource ? WebInspector.UIString("view parsed") : WebInspector.UIString("view source");
  448. var viewSourceToggleButton = this._createToggleButton(viewSourceToggleTitle);
  449. viewSourceToggleButton.addEventListener("click", toggleViewSource.bind(this));
  450. paramsTreeElement.listItemElement.appendChild(viewSourceToggleButton);
  451.  
  452. if (paramsTreeElement._viewSource) {
  453. this._populateTreeElementWithSourceText(paramsTreeElement, sourceText);
  454. return;
  455. }
  456.  
  457. var toggleTitle = this._decodeRequestParameters ? WebInspector.UIString("view URL encoded") : WebInspector.UIString("view decoded");
  458. var toggleButton = this._createToggleButton(toggleTitle);
  459. toggleButton.addEventListener("click", this._toggleURLDecoding.bind(this));
  460. paramsTreeElement.listItemElement.appendChild(toggleButton);
  461.  
  462. for (var i = 0; i < params.length; ++i) {
  463. var paramNameValue = document.createDocumentFragment();
  464. var name = this._formatParameter(params[i].name + ":", "header-name", this._decodeRequestParameters);
  465. var value = this._formatParameter(params[i].value, "header-value source-code", this._decodeRequestParameters);
  466. paramNameValue.appendChild(name);
  467. paramNameValue.appendChild(value);
  468.  
  469. var parmTreeElement = new TreeElement(paramNameValue, null, false);
  470. parmTreeElement.selectable = false;
  471. paramsTreeElement.appendChild(parmTreeElement);
  472. }
  473. },
  474.  
  475. _toggleURLDecoding: function(event)
  476. {
  477. this._decodeRequestParameters = !this._decodeRequestParameters;
  478. this._refreshQueryString();
  479. this._refreshFormData();
  480. },
  481.  
  482. _getHeaderValue: function(headers, key)
  483. {
  484. var lowerKey = key.toLowerCase();
  485. for (var testKey in headers) {
  486. if (testKey.toLowerCase() === lowerKey)
  487. return headers[testKey];
  488. }
  489. },
  490.  
  491. _refreshRequestHeaders: function()
  492. {
  493. var additionalRow = null;
  494. if (typeof this._request.webSocketRequestKey3 !== "undefined")
  495. additionalRow = {name: "(Key3)", value: this._request.webSocketRequestKey3};
  496. if (this._showRequestHeadersText)
  497. this._refreshHeadersText(WebInspector.UIString("Request Headers"), this._request.sortedRequestHeaders, this._request.requestHeadersText, this._requestHeadersTreeElement);
  498. else
  499. this._refreshHeaders(WebInspector.UIString("Request Headers"), this._request.sortedRequestHeaders, additionalRow, this._requestHeadersTreeElement);
  500.  
  501. if (this._request.requestHeadersText) {
  502. var toggleButton = this._createHeadersToggleButton(this._showRequestHeadersText);
  503. toggleButton.addEventListener("click", this._toggleRequestHeadersText.bind(this));
  504. this._requestHeadersTreeElement.listItemElement.appendChild(toggleButton);
  505. }
  506.  
  507. this._refreshFormData();
  508. },
  509.  
  510. _refreshResponseHeaders: function()
  511. {
  512. var additionalRow = null;
  513. if (typeof this._request.webSocketChallengeResponse !== "undefined")
  514. additionalRow = {name: "(Challenge Response)", value: this._request.webSocketChallengeResponse};
  515. if (this._showResponseHeadersText)
  516. this._refreshHeadersText(WebInspector.UIString("Response Headers"), this._request.sortedResponseHeaders, this._request.responseHeadersText, this._responseHeadersTreeElement);
  517. else
  518. this._refreshHeaders(WebInspector.UIString("Response Headers"), this._request.sortedResponseHeaders, additionalRow, this._responseHeadersTreeElement);
  519.  
  520. if (this._request.responseHeadersText) {
  521. var toggleButton = this._createHeadersToggleButton(this._showResponseHeadersText);
  522. toggleButton.addEventListener("click", this._toggleResponseHeadersText.bind(this));
  523. this._responseHeadersTreeElement.listItemElement.appendChild(toggleButton);
  524. }
  525. },
  526.  
  527. _refreshHTTPInformation: function()
  528. {
  529. var requestMethodElement = this._requestMethodTreeElement;
  530. requestMethodElement.hidden = !this._request.statusCode;
  531. var statusCodeElement = this._statusCodeTreeElement;
  532. statusCodeElement.hidden = !this._request.statusCode;
  533.  
  534. if (this._request.statusCode) {
  535. var statusImageSource = "";
  536. if (this._request.statusCode < 300 || this._request.statusCode === 304)
  537. statusImageSource = "Images/successGreenDot.png";
  538. else if (this._request.statusCode < 400)
  539. statusImageSource = "Images/warningOrangeDot.png";
  540. else
  541. statusImageSource = "Images/errorRedDot.png";
  542.  
  543. requestMethodElement.title = this._formatHeader(WebInspector.UIString("Request Method"), this._request.requestMethod);
  544.  
  545. var statusCodeFragment = document.createDocumentFragment();
  546. statusCodeFragment.createChild("div", "header-name").textContent = WebInspector.UIString("Status Code") + ":";
  547.  
  548. var statusCodeImage = statusCodeFragment.createChild("img", "resource-status-image");
  549. statusCodeImage.src = statusImageSource;
  550. statusCodeImage.title = this._request.statusCode + " " + this._request.statusText;
  551. var value = statusCodeFragment.createChild("div", "header-value source-code");
  552. value.textContent = this._request.statusCode + " " + this._request.statusText;
  553. if (this._request.cached)
  554. value.createChild("span", "status-from-cache").textContent = " " + WebInspector.UIString("(from cache)");
  555.  
  556. statusCodeElement.title = statusCodeFragment;
  557. }
  558. },
  559.  
  560. _refreshHeadersTitle: function(title, headersTreeElement, headersLength)
  561. {
  562. headersTreeElement.listItemElement.removeChildren();
  563. headersTreeElement.listItemElement.appendChild(document.createTextNode(title));
  564.  
  565. var headerCount = document.createElement("span");
  566. headerCount.addStyleClass("header-count");
  567. headerCount.textContent = WebInspector.UIString(" (%d)", headersLength);
  568. headersTreeElement.listItemElement.appendChild(headerCount);
  569. },
  570.  
  571. _refreshHeaders: function(title, headers, additionalRow, headersTreeElement)
  572. {
  573. headersTreeElement.removeChildren();
  574.  
  575. var length = headers.length;
  576. this._refreshHeadersTitle(title, headersTreeElement, length);
  577. headersTreeElement.hidden = !length;
  578. for (var i = 0; i < length; ++i) {
  579. var headerTreeElement = new TreeElement(null, null, false);
  580. headerTreeElement.title = this._formatHeader(headers[i].name, headers[i].value);
  581. headerTreeElement.selectable = false;
  582. headersTreeElement.appendChild(headerTreeElement);
  583. }
  584.  
  585. if (additionalRow) {
  586. var headerTreeElement = new TreeElement(null, null, false);
  587. headerTreeElement.title = this._formatHeader(additionalRow.name, additionalRow.value);
  588. headerTreeElement.selectable = false;
  589. headersTreeElement.appendChild(headerTreeElement);
  590. }
  591. },
  592.  
  593. _refreshHeadersText: function(title, headers, headersText, headersTreeElement)
  594. {
  595. this._populateTreeElementWithSourceText(headersTreeElement, headersText);
  596. this._refreshHeadersTitle(title, headersTreeElement, headers.length);
  597. },
  598.  
  599. _toggleRequestHeadersText: function(event)
  600. {
  601. this._showRequestHeadersText = !this._showRequestHeadersText;
  602. this._refreshRequestHeaders();
  603. },
  604.  
  605. _toggleResponseHeadersText: function(event)
  606. {
  607. this._showResponseHeadersText = !this._showResponseHeadersText;
  608. this._refreshResponseHeaders();
  609. },
  610.  
  611. _createToggleButton: function(title)
  612. {
  613. var button = document.createElement("span");
  614. button.addStyleClass("header-toggle");
  615. button.textContent = title;
  616. return button;
  617. },
  618.  
  619. _createHeadersToggleButton: function(isHeadersTextShown)
  620. {
  621. var toggleTitle = isHeadersTextShown ? WebInspector.UIString("view parsed") : WebInspector.UIString("view source");
  622. return this._createToggleButton(toggleTitle);
  623. },
  624.  
  625. __proto__: WebInspector.View.prototype
  626. }
  627. ;
  628.  
  629.  
  630.  
  631. WebInspector.RequestHTMLView = function(request, dataURL)
  632. {
  633. WebInspector.RequestView.call(this, request);
  634. this._dataURL = dataURL;
  635. this.element.addStyleClass("html");
  636. }
  637.  
  638. WebInspector.RequestHTMLView.prototype = {
  639. hasContent: function()
  640. {
  641. return true;
  642. },
  643.  
  644. wasShown: function()
  645. {
  646. this._createIFrame();
  647. },
  648.  
  649. willHide: function(parentElement)
  650. {
  651. this.element.removeChildren();
  652. },
  653.  
  654. _createIFrame: function()
  655. {
  656.  
  657.  
  658. this.element.removeChildren();
  659. var iframe = document.createElement("iframe");
  660. iframe.setAttribute("sandbox", ""); 
  661. iframe.setAttribute("src", this._dataURL);
  662. this.element.appendChild(iframe);
  663. },
  664.  
  665. __proto__: WebInspector.RequestView.prototype
  666. }
  667. ;
  668.  
  669.  
  670.  
  671. WebInspector.RequestJSONView = function(request, parsedJSON)
  672. {
  673. WebInspector.RequestView.call(this, request);
  674. this._parsedJSON = parsedJSON;
  675. this.element.addStyleClass("json");
  676. }
  677.  
  678. WebInspector.RequestJSONView.parseJSON = function(text)
  679. {
  680. var prefix = "";
  681.  
  682.  
  683. var start = /[{[]/.exec(text);
  684. if (start && start.index) {
  685. prefix = text.substring(0, start.index);
  686. text = text.substring(start.index);
  687. }
  688.  
  689. try {
  690. return new WebInspector.ParsedJSON(JSON.parse(text), prefix, "");
  691. } catch (e) {
  692. return;
  693. }
  694. }
  695.  
  696. WebInspector.RequestJSONView.parseJSONP = function(text)
  697. {
  698.  
  699. var start = text.indexOf("(");
  700. var end = text.lastIndexOf(")");
  701. if (start == -1 || end == -1 || end < start)
  702. return;
  703.  
  704. var prefix = text.substring(0, start + 1);
  705. var suffix = text.substring(end);
  706. text = text.substring(start + 1, end);
  707.  
  708. try {
  709. return new WebInspector.ParsedJSON(JSON.parse(text), prefix, suffix);
  710. } catch (e) {
  711. return;
  712. }
  713. }
  714.  
  715. WebInspector.RequestJSONView.prototype = {
  716. hasContent: function()
  717. {
  718. return true;
  719. },
  720.  
  721. wasShown: function()
  722. {
  723. this._initialize();
  724. },
  725.  
  726. _initialize: function()
  727. {
  728. if (this._initialized)
  729. return;
  730. this._initialized = true;
  731.  
  732. var obj = WebInspector.RemoteObject.fromLocalObject(this._parsedJSON.data);
  733. var title = this._parsedJSON.prefix + obj.description + this._parsedJSON.suffix;
  734. var section = new WebInspector.ObjectPropertiesSection(obj, title);
  735. section.expand();
  736. section.editable = false;
  737. this.element.appendChild(section.element);
  738. },
  739.  
  740. __proto__: WebInspector.RequestView.prototype
  741. }
  742.  
  743.  
  744. WebInspector.ParsedJSON = function(data, prefix, suffix)
  745. {
  746. this.data = data;
  747. this.prefix = prefix;
  748. this.suffix = suffix;
  749. }
  750. ;
  751.  
  752.  
  753.  
  754. WebInspector.RequestPreviewView = function(request, responseView)
  755. {
  756. WebInspector.RequestContentView.call(this, request);
  757. this._responseView = responseView;
  758. }
  759.  
  760. WebInspector.RequestPreviewView.prototype = {
  761. contentLoaded: function()
  762. {
  763. if (!this.request.content) {
  764. if (!this._emptyView) {
  765. this._emptyView = this._createEmptyView();
  766. this._emptyView.show(this.element);
  767. this.innerView = this._emptyView;
  768. }
  769. } else {
  770. if (this._emptyView) {
  771. this._emptyView.detach();
  772. delete this._emptyView;
  773. }
  774.  
  775. if (!this._previewView)
  776. this._previewView = this._createPreviewView();
  777. this._previewView.show(this.element);
  778. this.innerView = this._previewView;
  779. }
  780. },
  781.  
  782. _createEmptyView: function()
  783. {
  784. return new WebInspector.EmptyView(WebInspector.UIString("This request has no preview available."));
  785. },
  786.  
  787. _jsonView: function()
  788. {
  789. var parsedJSON = WebInspector.RequestJSONView.parseJSON(this.request.content);
  790. if (parsedJSON)
  791. return new WebInspector.RequestJSONView(this.request, parsedJSON);
  792. },
  793.  
  794. _htmlView: function()
  795. {
  796. var dataURL = this.request.asDataURL();
  797. if (dataURL !== null)
  798. return new WebInspector.RequestHTMLView(this.request, dataURL);
  799. },
  800.  
  801. _createPreviewView: function()
  802. {
  803. if (this.request.content) {
  804. if (this.request.hasErrorStatusCode()) {
  805. var htmlView = this._htmlView();
  806. if (htmlView)
  807. return htmlView;
  808. }
  809.  
  810. if (this.request.type === WebInspector.resourceTypes.XHR) {
  811. var jsonView = this._jsonView();
  812. if (jsonView)
  813. return jsonView;
  814. }
  815.  
  816. if (this.request.type === WebInspector.resourceTypes.XHR && this.request.mimeType === "text/html") {
  817. var htmlView = this._htmlView();
  818. if (htmlView)
  819. return htmlView;
  820. }
  821.  
  822. if (this.request.type === WebInspector.resourceTypes.Script && this.request.mimeType === "application/json") {
  823. var jsonView = this._jsonView();
  824. if (jsonView)
  825. return jsonView;
  826. }
  827. }
  828.  
  829. if (this._responseView.sourceView)
  830. return this._responseView.sourceView;
  831.  
  832. if (this.request.type === WebInspector.resourceTypes.Other)
  833. return this._createEmptyView();
  834.  
  835. return WebInspector.RequestView.nonSourceViewForRequest(this.request);
  836. },
  837.  
  838. __proto__: WebInspector.RequestContentView.prototype
  839. }
  840. ;
  841.  
  842.  
  843.  
  844. WebInspector.RequestResponseView = function(request)
  845. {
  846. WebInspector.RequestContentView.call(this, request);
  847. }
  848.  
  849. WebInspector.RequestResponseView.prototype = {
  850. get sourceView()
  851. {
  852. if (!this._sourceView && WebInspector.RequestView.hasTextContent(this.request))
  853. this._sourceView = new WebInspector.ResourceSourceFrame(this.request);
  854. return this._sourceView;
  855. },
  856.  
  857. contentLoaded: function()
  858. {
  859. if (!this.request.content || !this.sourceView) {
  860. if (!this._emptyView) {
  861. this._emptyView = new WebInspector.EmptyView(WebInspector.UIString("This request has no response data available."));
  862. this._emptyView.show(this.element);
  863. this.innerView = this._emptyView;
  864. }
  865. } else {
  866. if (this._emptyView) {
  867. this._emptyView.detach();
  868. delete this._emptyView;
  869. }
  870.  
  871. this.sourceView.show(this.element);
  872. this.innerView = this.sourceView;
  873. }
  874. },
  875.  
  876. __proto__: WebInspector.RequestContentView.prototype
  877. }
  878. ;
  879.  
  880.  
  881.  
  882. WebInspector.RequestTimingView = function(request)
  883. {
  884. WebInspector.View.call(this);
  885. this.element.addStyleClass("resource-timing-view");
  886.  
  887. this._request = request;
  888.  
  889. request.addEventListener(WebInspector.NetworkRequest.Events.TimingChanged, this._refresh, this);
  890. }
  891.  
  892. WebInspector.RequestTimingView.prototype = {
  893. wasShown: function()
  894. {
  895. if (!this._request.timing) {
  896. if (!this._emptyView) {
  897. this._emptyView = new WebInspector.EmptyView(WebInspector.UIString("This request has no detailed timing info."));
  898. this._emptyView.show(this.element);
  899. this.innerView = this._emptyView;
  900. }
  901. return;
  902. }
  903.  
  904. if (this._emptyView) {
  905. this._emptyView.detach();
  906. delete this._emptyView;
  907. }
  908.  
  909. this._refresh();
  910. },
  911.  
  912. _refresh: function()
  913. {
  914. if (this._tableElement)
  915. this._tableElement.parentElement.removeChild(this._tableElement);
  916.  
  917. this._tableElement = WebInspector.RequestTimingView.createTimingTable(this._request);
  918. this.element.appendChild(this._tableElement);
  919. },
  920.  
  921. __proto__: WebInspector.View.prototype
  922. }
  923.  
  924.  
  925. WebInspector.RequestTimingView.createTimingTable = function(request)
  926. {
  927. var tableElement = document.createElement("table");
  928. var rows = [];
  929.  
  930. function addRow(title, className, start, end)
  931. {
  932. var row = {};
  933. row.title = title;
  934. row.className = className;
  935. row.start = start;
  936. row.end = end;
  937. rows.push(row);
  938. }
  939.  
  940. if (request.timing.proxyStart !== -1)
  941. addRow(WebInspector.UIString("Proxy"), "proxy", request.timing.proxyStart, request.timing.proxyEnd);
  942.  
  943. if (request.timing.dnsStart !== -1)
  944. addRow(WebInspector.UIString("DNS Lookup"), "dns", request.timing.dnsStart, request.timing.dnsEnd);
  945.  
  946. if (request.timing.connectStart !== -1) {
  947. if (request.connectionReused)
  948. addRow(WebInspector.UIString("Blocking"), "connecting", request.timing.connectStart, request.timing.connectEnd);
  949. else {
  950. var connectStart = request.timing.connectStart;
  951.  
  952. if (request.timing.dnsStart !== -1)
  953. connectStart += request.timing.dnsEnd - request.timing.dnsStart;
  954. addRow(WebInspector.UIString("Connecting"), "connecting", connectStart, request.timing.connectEnd);
  955. }
  956. }
  957.  
  958. if (request.timing.sslStart !== -1)
  959. addRow(WebInspector.UIString("SSL"), "ssl", request.timing.sslStart, request.timing.sslEnd);
  960.  
  961. var sendStart = request.timing.sendStart;
  962. if (request.timing.sslStart !== -1)
  963. sendStart += request.timing.sslEnd - request.timing.sslStart;
  964.  
  965. addRow(WebInspector.UIString("Sending"), "sending", request.timing.sendStart, request.timing.sendEnd);
  966. addRow(WebInspector.UIString("Waiting"), "waiting", request.timing.sendEnd, request.timing.receiveHeadersEnd);
  967. addRow(WebInspector.UIString("Receiving"), "receiving", (request.responseReceivedTime - request.timing.requestTime) * 1000, (request.endTime - request.timing.requestTime) * 1000);
  968.  
  969. const chartWidth = 200;
  970. var total = (request.endTime - request.timing.requestTime) * 1000;
  971. var scale = chartWidth / total;
  972.  
  973. for (var i = 0; i < rows.length; ++i) {
  974. var tr = document.createElement("tr");
  975. tableElement.appendChild(tr);
  976.  
  977. var td = document.createElement("td");
  978. td.textContent = rows[i].title;
  979. tr.appendChild(td);
  980.  
  981. td = document.createElement("td");
  982. td.width = chartWidth + "px";
  983.  
  984. var row = document.createElement("div");
  985. row.className = "network-timing-row";
  986. td.appendChild(row);
  987.  
  988. var bar = document.createElement("span");
  989. bar.className = "network-timing-bar " + rows[i].className;
  990. bar.style.left = scale * rows[i].start + "px";
  991. bar.style.right = scale * (total - rows[i].end) + "px";
  992. bar.style.backgroundColor = rows[i].color;
  993. bar.textContent = "\u200B"; 
  994. row.appendChild(bar);
  995.  
  996. var title = document.createElement("span");
  997. title.className = "network-timing-bar-title";
  998. if (total - rows[i].end < rows[i].start)
  999. title.style.right = (scale * (total - rows[i].end) + 3) + "px";
  1000. else
  1001. title.style.left = (scale * rows[i].start + 3) + "px";
  1002. title.textContent = Number.secondsToString((rows[i].end - rows[i].start) / 1000);
  1003. row.appendChild(title);
  1004.  
  1005. tr.appendChild(td);
  1006. }
  1007. return tableElement;
  1008. }
  1009. ;
  1010.  
  1011.  
  1012.  
  1013. WebInspector.ResourceWebSocketFrameView = function(resource)
  1014. {
  1015. WebInspector.View.call(this);
  1016. this.element.addStyleClass("resource-websocket");
  1017. this.resource = resource;
  1018. this.element.removeChildren();
  1019.  
  1020. var dataGrid = new WebInspector.DataGrid({
  1021. data: {title: WebInspector.UIString("Data"), sortable: false},
  1022. length: {title: WebInspector.UIString("Length"), sortable: false, aligned: "right", width: "50px"},
  1023. time: {title: WebInspector.UIString("Time"), width: "70px"}
  1024. });
  1025.  
  1026. var frames = this.resource.frames();
  1027. for (var i = 0; i < frames.length; i++) {
  1028. var payload = frames[i];
  1029.  
  1030. var date = new Date(payload.time * 1000);
  1031. var row = {
  1032. data: "",
  1033. length: payload.payloadData.length.toString(),
  1034. time: date.toLocaleTimeString()
  1035. };
  1036.  
  1037. var rowClass = "";
  1038. if (payload.errorMessage) {
  1039. rowClass = "error";
  1040. row.data = payload.errorMessage;
  1041. } else if (payload.opcode == WebInspector.ResourceWebSocketFrameView.OpCodes.TextFrame) {
  1042. if (payload.sent)
  1043. rowClass = "outcoming";
  1044.  
  1045. row.data = payload.payloadData;
  1046. } else {
  1047. rowClass = "opcode";
  1048. var opcodeMeaning = "";
  1049. switch (payload.opcode) {
  1050. case WebInspector.ResourceWebSocketFrameView.OpCodes.ContinuationFrame:
  1051. opcodeMeaning = WebInspector.UIString("Continuation Frame");
  1052. break;
  1053. case WebInspector.ResourceWebSocketFrameView.OpCodes.BinaryFrame:
  1054. opcodeMeaning = WebInspector.UIString("Binary Frame");
  1055. break;
  1056. case WebInspector.ResourceWebSocketFrameView.OpCodes.ConnectionCloseFrame:
  1057. opcodeMeaning = WebInspector.UIString("Connection Close Frame");
  1058. break;
  1059. case WebInspector.ResourceWebSocketFrameView.OpCodes.PingFrame:
  1060. opcodeMeaning = WebInspector.UIString("Ping Frame");
  1061. break;
  1062. case WebInspector.ResourceWebSocketFrameView.OpCodes.PongFrame:
  1063. opcodeMeaning = WebInspector.UIString("Pong Frame");
  1064. break;
  1065. }
  1066. row.data = WebInspector.UIString("%s (Opcode %d%s)", opcodeMeaning, payload.opcode, (payload.mask ? ", mask" : ""));
  1067. }
  1068.  
  1069. var node = new WebInspector.DataGridNode(row, false);
  1070. dataGrid.rootNode().appendChild(node);
  1071.  
  1072. if (rowClass)
  1073. node.element.classList.add("resource-websocket-row-" + rowClass);
  1074.  
  1075. }
  1076. dataGrid.show(this.element);
  1077. }
  1078.  
  1079. WebInspector.ResourceWebSocketFrameView.OpCodes = {
  1080. ContinuationFrame: 0,
  1081. TextFrame: 1,
  1082. BinaryFrame: 2,
  1083. ConnectionCloseFrame: 8,
  1084. PingFrame: 9,
  1085. PongFrame: 10
  1086. };
  1087.  
  1088. WebInspector.ResourceWebSocketFrameView.prototype = {
  1089. __proto__: WebInspector.View.prototype
  1090. }
  1091. ;
  1092.  
  1093.  
  1094. WebInspector.NetworkLogView = function()
  1095. {
  1096. WebInspector.View.call(this);
  1097. this.registerRequiredCSS("networkLogView.css");
  1098.  
  1099. this._allowRequestSelection = false;
  1100. this._requests = [];
  1101. this._requestsById = {};
  1102. this._requestsByURL = {};
  1103. this._staleRequests = {};
  1104. this._requestGridNodes = {};
  1105. this._lastRequestGridNodeId = 0;
  1106. this._mainRequestLoadTime = -1;
  1107. this._mainRequestDOMContentTime = -1;
  1108. this._hiddenCategories = {};
  1109. this._matchedRequests = [];
  1110. this._highlightedSubstringChanges = [];
  1111. this._filteredOutRequests = new Map();
  1112.  
  1113. this._matchedRequestsMap = {};
  1114. this._currentMatchedRequestIndex = -1;
  1115.  
  1116. this._createStatusbarButtons();
  1117. this._createStatusBarItems();
  1118. this._linkifier = new WebInspector.Linkifier();
  1119.  
  1120. WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.RequestStarted, this._onRequestStarted, this);
  1121. WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.RequestUpdated, this._onRequestUpdated, this);
  1122. WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.RequestFinished, this._onRequestUpdated, this);
  1123.  
  1124. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.MainFrameNavigated, this._mainFrameNavigated, this);
  1125. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.OnLoad, this._onLoadEventFired, this);
  1126. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.DOMContentLoaded, this._domContentLoadedEventFired, this);
  1127.  
  1128. this._initializeView();
  1129. function onCanClearBrowserCache(error, result)
  1130. {
  1131. this._canClearBrowserCache = result;
  1132. }
  1133. NetworkAgent.canClearBrowserCache(onCanClearBrowserCache.bind(this));
  1134.  
  1135. function onCanClearBrowserCookies(error, result)
  1136. {
  1137. this._canClearBrowserCookies = result;
  1138. }
  1139. NetworkAgent.canClearBrowserCookies(onCanClearBrowserCookies.bind(this));
  1140.  
  1141. WebInspector.networkLog.requests.forEach(this._appendRequest.bind(this));
  1142. }
  1143.  
  1144. WebInspector.NetworkLogView.prototype = {
  1145. _initializeView: function()
  1146. {
  1147. this.element.id = "network-container";
  1148.  
  1149. this._createSortingFunctions();
  1150. this._createTable();
  1151. this._createTimelineGrid();
  1152. this._createSummaryBar();
  1153.  
  1154. if (!this.useLargeRows)
  1155. this._setLargerRequests(this.useLargeRows);
  1156.  
  1157. this._allowPopover = true;
  1158. this._popoverHelper = new WebInspector.PopoverHelper(this.element, this._getPopoverAnchor.bind(this), this._showPopover.bind(this));
  1159.  
  1160. this._popoverHelper.setTimeout(100);
  1161.  
  1162. this.calculator = new WebInspector.NetworkTransferTimeCalculator();
  1163. this._filter(this._filterAllElement, false);
  1164.  
  1165. this.switchToDetailedView();
  1166. },
  1167.  
  1168. get statusBarItems()
  1169. {
  1170. return [this._largerRequestsButton.element, this._preserveLogToggle.element, this._clearButton.element, this._filterBarElement, this._progressBarContainer];
  1171. },
  1172.  
  1173. get useLargeRows()
  1174. {
  1175. return WebInspector.settings.resourcesLargeRows.get();
  1176. },
  1177.  
  1178. set allowPopover(flag)
  1179. {
  1180. this._allowPopover = flag;
  1181. },
  1182.  
  1183. elementsToRestoreScrollPositionsFor: function()
  1184. {
  1185. if (!this._dataGrid) 
  1186. return [];
  1187. return [this._dataGrid.scrollContainer];
  1188. },
  1189.  
  1190. onResize: function()
  1191. {
  1192. this._updateOffscreenRows();
  1193. },
  1194.  
  1195. _createTimelineGrid: function()
  1196. {
  1197. this._timelineGrid = new WebInspector.TimelineGrid();
  1198. this._timelineGrid.element.addStyleClass("network-timeline-grid");
  1199. this._dataGrid.element.appendChild(this._timelineGrid.element);
  1200. },
  1201.  
  1202. _createTable: function()
  1203. {
  1204. var columns = {name: {}, method: {}, status: {}, type: {}, initiator: {}, size: {}, time: {}, timeline: {}};
  1205.  
  1206. columns.name.titleDOMFragment = this._makeHeaderFragment(WebInspector.UIString("Name"), WebInspector.UIString("Path"));
  1207. columns.name.sortable = true;
  1208. columns.name.width = "20%";
  1209. columns.name.disclosure = true;
  1210.  
  1211. columns.method.title = WebInspector.UIString("Method");
  1212. columns.method.sortable = true;
  1213. columns.method.width = "6%";
  1214.  
  1215. columns.status.titleDOMFragment = this._makeHeaderFragment(WebInspector.UIString("Status"), WebInspector.UIString("Text"));
  1216. columns.status.sortable = true;
  1217. columns.status.width = "6%";
  1218.  
  1219. columns.type.title = WebInspector.UIString("Type");
  1220. columns.type.sortable = true;
  1221. columns.type.width = "6%";
  1222.  
  1223. columns.initiator.title = WebInspector.UIString("Initiator");
  1224. columns.initiator.sortable = true;
  1225. columns.initiator.width = "10%";
  1226.  
  1227. columns.size.titleDOMFragment = this._makeHeaderFragment(WebInspector.UIString("Size"), WebInspector.UIString("Content"));
  1228. columns.size.sortable = true;
  1229. columns.size.width = "6%";
  1230. columns.size.aligned = "right";
  1231.  
  1232. columns.time.titleDOMFragment = this._makeHeaderFragment(WebInspector.UIString("Time"), WebInspector.UIString("Latency"));
  1233. columns.time.sortable = true;
  1234. columns.time.width = "6%";
  1235. columns.time.aligned = "right";
  1236.  
  1237. columns.timeline.title = "";
  1238. columns.timeline.sortable = false;
  1239. columns.timeline.width = "40%";
  1240. columns.timeline.sort = "ascending";
  1241.  
  1242. this._dataGrid = new WebInspector.DataGrid(columns);
  1243. this._dataGrid.resizeMethod = WebInspector.DataGrid.ResizeMethod.Last;
  1244. this._dataGrid.element.addStyleClass("network-log-grid");
  1245. this._dataGrid.element.addEventListener("contextmenu", this._contextMenu.bind(this), true);
  1246. this._dataGrid.show(this.element);
  1247.  
  1248.  
  1249. this._dataGrid.addEventListener("sorting changed", this._sortItems, this);
  1250. this._dataGrid.addEventListener("width changed", this._updateDividersIfNeeded, this);
  1251. this._dataGrid.scrollContainer.addEventListener("scroll", this._updateOffscreenRows.bind(this));
  1252.  
  1253. this._patchTimelineHeader();
  1254. },
  1255.  
  1256. _makeHeaderFragment: function(title, subtitle)
  1257. {
  1258. var fragment = document.createDocumentFragment();
  1259. fragment.appendChild(document.createTextNode(title));
  1260. var subtitleDiv = document.createElement("div");
  1261. subtitleDiv.className = "network-header-subtitle";
  1262. subtitleDiv.textContent = subtitle;
  1263. fragment.appendChild(subtitleDiv);
  1264. return fragment;
  1265. },
  1266.  
  1267. _patchTimelineHeader: function()
  1268. {
  1269. var timelineSorting = document.createElement("select");
  1270.  
  1271. var option = document.createElement("option");
  1272. option.value = "startTime";
  1273. option.label = WebInspector.UIString("Timeline");
  1274. timelineSorting.appendChild(option);
  1275.  
  1276. option = document.createElement("option");
  1277. option.value = "startTime";
  1278. option.label = WebInspector.UIString("Start Time");
  1279. timelineSorting.appendChild(option);
  1280.  
  1281. option = document.createElement("option");
  1282. option.value = "responseTime";
  1283. option.label = WebInspector.UIString("Response Time");
  1284. timelineSorting.appendChild(option);
  1285.  
  1286. option = document.createElement("option");
  1287. option.value = "endTime";
  1288. option.label = WebInspector.UIString("End Time");
  1289. timelineSorting.appendChild(option);
  1290.  
  1291. option = document.createElement("option");
  1292. option.value = "duration";
  1293. option.label = WebInspector.UIString("Duration");
  1294. timelineSorting.appendChild(option);
  1295.  
  1296. option = document.createElement("option");
  1297. option.value = "latency";
  1298. option.label = WebInspector.UIString("Latency");
  1299. timelineSorting.appendChild(option);
  1300.  
  1301. var header = this._dataGrid.headerTableHeader("timeline");
  1302. header.replaceChild(timelineSorting, header.firstChild);
  1303.  
  1304. timelineSorting.addEventListener("click", function(event) { event.consume() }, false);
  1305. timelineSorting.addEventListener("change", this._sortByTimeline.bind(this), false);
  1306. this._timelineSortSelector = timelineSorting;
  1307. },
  1308.  
  1309. _createSortingFunctions: function()
  1310. {
  1311. this._sortingFunctions = {};
  1312. this._sortingFunctions.name = WebInspector.NetworkDataGridNode.NameComparator;
  1313. this._sortingFunctions.method = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "method", false);
  1314. this._sortingFunctions.status = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "statusCode", false);
  1315. this._sortingFunctions.type = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "mimeType", false);
  1316. this._sortingFunctions.initiator = WebInspector.NetworkDataGridNode.InitiatorComparator;
  1317. this._sortingFunctions.size = WebInspector.NetworkDataGridNode.SizeComparator;
  1318. this._sortingFunctions.time = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "duration", false);
  1319. this._sortingFunctions.timeline = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "startTime", false);
  1320. this._sortingFunctions.startTime = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "startTime", false);
  1321. this._sortingFunctions.endTime = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "endTime", false);
  1322. this._sortingFunctions.responseTime = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "responseReceivedTime", false);
  1323. this._sortingFunctions.duration = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "duration", true);
  1324. this._sortingFunctions.latency = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "latency", true);
  1325.  
  1326. var timeCalculator = new WebInspector.NetworkTransferTimeCalculator();
  1327. var durationCalculator = new WebInspector.NetworkTransferDurationCalculator();
  1328.  
  1329. this._calculators = {};
  1330. this._calculators.timeline = timeCalculator;
  1331. this._calculators.startTime = timeCalculator;
  1332. this._calculators.endTime = timeCalculator;
  1333. this._calculators.responseTime = timeCalculator;
  1334. this._calculators.duration = durationCalculator;
  1335. this._calculators.latency = durationCalculator;
  1336. },
  1337.  
  1338. _sortItems: function()
  1339. {
  1340. this._removeAllNodeHighlights();
  1341. var columnIdentifier = this._dataGrid.sortColumnIdentifier;
  1342. if (columnIdentifier === "timeline") {
  1343. this._sortByTimeline();
  1344. return;
  1345. }
  1346. var sortingFunction = this._sortingFunctions[columnIdentifier];
  1347. if (!sortingFunction)
  1348. return;
  1349.  
  1350. this._dataGrid.sortNodes(sortingFunction, this._dataGrid.sortOrder === "descending");
  1351. this._timelineSortSelector.selectedIndex = 0;
  1352. this._updateOffscreenRows();
  1353.  
  1354. this.searchCanceled();
  1355.  
  1356. WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMetrics.UserAction, {
  1357. action: WebInspector.UserMetrics.UserActionNames.NetworkSort,
  1358. column: columnIdentifier,
  1359. sortOrder: this._dataGrid.sortOrder
  1360. });
  1361. },
  1362.  
  1363. _sortByTimeline: function()
  1364. {
  1365. this._removeAllNodeHighlights();
  1366. var selectedIndex = this._timelineSortSelector.selectedIndex;
  1367. if (!selectedIndex)
  1368. selectedIndex = 1; 
  1369. var selectedOption = this._timelineSortSelector[selectedIndex];
  1370. var value = selectedOption.value;
  1371.  
  1372. var sortingFunction = this._sortingFunctions[value];
  1373. this._dataGrid.sortNodes(sortingFunction);
  1374. this.calculator = this._calculators[value];
  1375. if (this.calculator.startAtZero)
  1376. this._timelineGrid.hideEventDividers();
  1377. else
  1378. this._timelineGrid.showEventDividers();
  1379. this._dataGrid.markColumnAsSortedBy("timeline", "ascending");
  1380. this._updateOffscreenRows();
  1381. },
  1382.  
  1383. _createStatusBarItems: function()
  1384. {
  1385. var filterBarElement = document.createElement("div");
  1386. filterBarElement.className = "scope-bar status-bar-item";
  1387.  
  1388.  
  1389. function createFilterElement(typeName, label)
  1390. {
  1391. var categoryElement = document.createElement("li");
  1392. categoryElement.typeName = typeName;
  1393. categoryElement.className = typeName;
  1394. categoryElement.appendChild(document.createTextNode(label));
  1395. categoryElement.addEventListener("click", this._updateFilter.bind(this), false);
  1396. filterBarElement.appendChild(categoryElement);
  1397.  
  1398. return categoryElement;
  1399. }
  1400.  
  1401. this._filterAllElement = createFilterElement.call(this, "all", WebInspector.UIString("All"));
  1402.  
  1403.  
  1404. var dividerElement = document.createElement("div");
  1405. dividerElement.addStyleClass("scope-bar-divider");
  1406. filterBarElement.appendChild(dividerElement);
  1407.  
  1408. for (var typeId in WebInspector.resourceTypes) {
  1409. var type = WebInspector.resourceTypes[typeId];
  1410. createFilterElement.call(this, type.name(), type.categoryTitle());
  1411. }
  1412. this._filterBarElement = filterBarElement;
  1413. this._progressBarContainer = document.createElement("div");
  1414. this._progressBarContainer.className = "status-bar-item";
  1415. },
  1416.  
  1417. _createSummaryBar: function()
  1418. {
  1419. var tbody = this._dataGrid.dataTableBody;
  1420. var tfoot = document.createElement("tfoot");
  1421. var tr = tfoot.createChild("tr", "revealed network-summary-bar");
  1422. var td = tr.createChild("td");
  1423. td.setAttribute("colspan", 7);
  1424. tbody.parentNode.insertBefore(tfoot, tbody);
  1425. this._summaryBarElement = td;
  1426. },
  1427.  
  1428. _updateSummaryBar: function()
  1429. {
  1430. var requestsNumber = this._requests.length;
  1431.  
  1432. if (!requestsNumber) {
  1433. if (this._summaryBarElement._isDisplayingWarning)
  1434. return;
  1435. this._summaryBarElement._isDisplayingWarning = true;
  1436.  
  1437. var img = document.createElement("img");
  1438. img.src = "Images/warningIcon.png";
  1439. this._summaryBarElement.removeChildren();
  1440. this._summaryBarElement.appendChild(img);
  1441. this._summaryBarElement.appendChild(document.createTextNode(
  1442. WebInspector.UIString("No requests captured. Reload the page to see detailed information on the network activity.")));
  1443. return;
  1444. }
  1445. delete this._summaryBarElement._isDisplayingWarning;
  1446.  
  1447. var transferSize = 0;
  1448. var selectedRequestsNumber = 0;
  1449. var selectedTransferSize = 0;
  1450. var baseTime = -1;
  1451. var maxTime = -1;
  1452. for (var i = 0; i < this._requests.length; ++i) {
  1453. var request = this._requests[i];
  1454. var requestTransferSize = (request.cached || !request.transferSize) ? 0 : request.transferSize;
  1455. transferSize += requestTransferSize;
  1456. if ((!this._hiddenCategories.all || !this._hiddenCategories[request.type.name()]) && !this._filteredOutRequests.get(request)) {
  1457. selectedRequestsNumber++;
  1458. selectedTransferSize += requestTransferSize;
  1459. }
  1460. if (request.url === WebInspector.inspectedPageURL)
  1461. baseTime = request.startTime;
  1462. if (request.endTime > maxTime)
  1463. maxTime = request.endTime;
  1464. }
  1465. var text = "";
  1466. if (selectedRequestsNumber !== requestsNumber) {
  1467. text += String.sprintf(WebInspector.UIString("%d / %d requests"), selectedRequestsNumber, requestsNumber);
  1468. text += "  \u2758  " + String.sprintf(WebInspector.UIString("%s / %s transferred"), Number.bytesToString(selectedTransferSize), Number.bytesToString(transferSize));
  1469. } else {
  1470. text += String.sprintf(WebInspector.UIString("%d requests"), requestsNumber);
  1471. text += "  \u2758  " + String.sprintf(WebInspector.UIString("%s transferred"), Number.bytesToString(transferSize));
  1472. }
  1473. if (baseTime !== -1 && this._mainRequestLoadTime !== -1 && this._mainRequestDOMContentTime !== -1 && this._mainRequestDOMContentTime > baseTime) {
  1474. text += "  \u2758  " + String.sprintf(WebInspector.UIString("%s (onload: %s, DOMContentLoaded: %s)"),
  1475. Number.secondsToString(maxTime - baseTime),
  1476. Number.secondsToString(this._mainRequestLoadTime - baseTime),
  1477. Number.secondsToString(this._mainRequestDOMContentTime - baseTime));
  1478. }
  1479. this._summaryBarElement.textContent = text;
  1480. },
  1481.  
  1482. _showCategory: function(typeName)
  1483. {
  1484. this._dataGrid.element.addStyleClass("filter-" + typeName);
  1485. delete this._hiddenCategories[typeName];
  1486. },
  1487.  
  1488. _hideCategory: function(typeName)
  1489. {
  1490. this._dataGrid.element.removeStyleClass("filter-" + typeName);
  1491. this._hiddenCategories[typeName] = true;
  1492. },
  1493.  
  1494. _updateFilter: function(e)
  1495. {
  1496. this._removeAllNodeHighlights();
  1497. var isMac = WebInspector.isMac();
  1498. var selectMultiple = false;
  1499. if (isMac && e.metaKey && !e.ctrlKey && !e.altKey && !e.shiftKey)
  1500. selectMultiple = true;
  1501. if (!isMac && e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey)
  1502. selectMultiple = true;
  1503.  
  1504. this._filter(e.target, selectMultiple);
  1505. this.searchCanceled();
  1506. this._updateSummaryBar();
  1507. },
  1508.  
  1509. _filter: function(target, selectMultiple)
  1510. {
  1511. function unselectAll()
  1512. {
  1513. for (var i = 0; i < this._filterBarElement.childNodes.length; ++i) {
  1514. var child = this._filterBarElement.childNodes[i];
  1515. if (!child.typeName)
  1516. continue;
  1517.  
  1518. child.removeStyleClass("selected");
  1519. this._hideCategory(child.typeName);
  1520. }
  1521. }
  1522.  
  1523. if (target === this._filterAllElement) {
  1524. if (target.hasStyleClass("selected")) {
  1525.  
  1526. return;
  1527. }
  1528.  
  1529.  
  1530. unselectAll.call(this);
  1531. } else {
  1532.  
  1533. if (this._filterAllElement.hasStyleClass("selected")) {
  1534. this._filterAllElement.removeStyleClass("selected");
  1535. this._hideCategory("all");
  1536. }
  1537. }
  1538.  
  1539. if (!selectMultiple) {
  1540.  
  1541.  
  1542. unselectAll.call(this);
  1543.  
  1544. target.addStyleClass("selected");
  1545. this._showCategory(target.typeName);
  1546. this._updateOffscreenRows();
  1547. return;
  1548. }
  1549.  
  1550. if (target.hasStyleClass("selected")) {
  1551.  
  1552.  
  1553. target.removeStyleClass("selected");
  1554. this._hideCategory(target.typeName);
  1555. } else {
  1556.  
  1557.  
  1558. target.addStyleClass("selected");
  1559. this._showCategory(target.typeName);
  1560. }
  1561. this._updateOffscreenRows();
  1562. },
  1563.  
  1564. _defaultRefreshDelay: 500,
  1565.  
  1566. _scheduleRefresh: function()
  1567. {
  1568. if (this._needsRefresh)
  1569. return;
  1570.  
  1571. this._needsRefresh = true;
  1572.  
  1573. if (this.isShowing() && !this._refreshTimeout)
  1574. this._refreshTimeout = setTimeout(this.refresh.bind(this), this._defaultRefreshDelay);
  1575. },
  1576.  
  1577. _updateDividersIfNeeded: function()
  1578. {
  1579. if (!this._dataGrid)
  1580. return;
  1581. var timelineColumn = this._dataGrid.columns.timeline;
  1582. for (var i = 0; i < this._dataGrid.resizers.length; ++i) {
  1583. if (timelineColumn.ordinal === this._dataGrid.resizers[i].rightNeighboringColumnID) {
  1584.  
  1585. this._timelineGrid.element.style.left = this._dataGrid.resizers[i].style.left;
  1586. this._timelineGrid.element.style.right = "18px";
  1587. }
  1588. }
  1589.  
  1590. var proceed = true;
  1591. if (!this.isShowing()) {
  1592. this._scheduleRefresh();
  1593. proceed = false;
  1594. } else {
  1595. this.calculator.setDisplayWindow(this._timelineGrid.element.clientWidth);
  1596. proceed = this._timelineGrid.updateDividers(this.calculator);
  1597. }
  1598. if (!proceed)
  1599. return;
  1600.  
  1601. if (this.calculator.startAtZero || !this.calculator.computePercentageFromEventTime) {
  1602.  
  1603.  
  1604.  
  1605.  
  1606.  
  1607.  
  1608. return;
  1609. }
  1610.  
  1611. this._timelineGrid.removeEventDividers();
  1612. if (this._mainRequestLoadTime !== -1) {
  1613. var percent = this.calculator.computePercentageFromEventTime(this._mainRequestLoadTime);
  1614.  
  1615. var loadDivider = document.createElement("div");
  1616. loadDivider.className = "network-event-divider network-red-divider";
  1617.  
  1618. var loadDividerPadding = document.createElement("div");
  1619. loadDividerPadding.className = "network-event-divider-padding";
  1620. loadDividerPadding.title = WebInspector.UIString("Load event fired");
  1621. loadDividerPadding.appendChild(loadDivider);
  1622. loadDividerPadding.style.left = percent + "%";
  1623. this._timelineGrid.addEventDivider(loadDividerPadding);
  1624. }
  1625.  
  1626. if (this._mainRequestDOMContentTime !== -1) {
  1627. var percent = this.calculator.computePercentageFromEventTime(this._mainRequestDOMContentTime);
  1628.  
  1629. var domContentDivider = document.createElement("div");
  1630. domContentDivider.className = "network-event-divider network-blue-divider";
  1631.  
  1632. var domContentDividerPadding = document.createElement("div");
  1633. domContentDividerPadding.className = "network-event-divider-padding";
  1634. domContentDividerPadding.title = WebInspector.UIString("DOMContent event fired");
  1635. domContentDividerPadding.appendChild(domContentDivider);
  1636. domContentDividerPadding.style.left = percent + "%";
  1637. this._timelineGrid.addEventDivider(domContentDividerPadding);
  1638. }
  1639. },
  1640.  
  1641. _refreshIfNeeded: function()
  1642. {
  1643. if (this._needsRefresh)
  1644. this.refresh();
  1645. },
  1646.  
  1647. _invalidateAllItems: function()
  1648. {
  1649. for (var i = 0; i < this._requests.length; ++i) {
  1650. var request = this._requests[i];
  1651. this._staleRequests[request.requestId] = request;
  1652. }
  1653. },
  1654.  
  1655. get calculator()
  1656. {
  1657. return this._calculator;
  1658. },
  1659.  
  1660. set calculator(x)
  1661. {
  1662. if (!x || this._calculator === x)
  1663. return;
  1664.  
  1665. this._calculator = x;
  1666. this._calculator.reset();
  1667.  
  1668. this._invalidateAllItems();
  1669. this.refresh();
  1670. },
  1671.  
  1672. _requestGridNode: function(request)
  1673. {
  1674. return this._requestGridNodes[request.__gridNodeId];
  1675. },
  1676.  
  1677. _createRequestGridNode: function(request)
  1678. {
  1679. var node = new WebInspector.NetworkDataGridNode(this, request);
  1680. request.__gridNodeId = this._lastRequestGridNodeId++;
  1681. this._requestGridNodes[request.__gridNodeId] = node;
  1682. return node;
  1683. },
  1684.  
  1685. _createStatusbarButtons: function()
  1686. {
  1687. this._preserveLogToggle = new WebInspector.StatusBarButton(WebInspector.UIString("Preserve Log upon Navigation"), "record-profile-status-bar-item");
  1688. this._preserveLogToggle.addEventListener("click", this._onPreserveLogClicked, this);
  1689.  
  1690. this._clearButton = new WebInspector.StatusBarButton(WebInspector.UIString("Clear"), "clear-status-bar-item");
  1691. this._clearButton.addEventListener("click", this._reset, this);
  1692.  
  1693. this._largerRequestsButton = new WebInspector.StatusBarButton(WebInspector.UIString("Use small resource rows."), "network-larger-resources-status-bar-item");
  1694. this._largerRequestsButton.toggled = WebInspector.settings.resourcesLargeRows.get();
  1695. this._largerRequestsButton.addEventListener("click", this._toggleLargerRequests, this);
  1696. },
  1697.  
  1698. _onLoadEventFired: function(event)
  1699. {
  1700. this._mainRequestLoadTime = event.data || -1;
  1701.  
  1702. this._scheduleRefresh();
  1703. },
  1704.  
  1705. _domContentLoadedEventFired: function(event)
  1706. {
  1707. this._mainRequestDOMContentTime = event.data || -1;
  1708.  
  1709. this._scheduleRefresh();
  1710. },
  1711.  
  1712. wasShown: function()
  1713. {
  1714. this._refreshIfNeeded();
  1715. },
  1716.  
  1717. willHide: function()
  1718. {
  1719. this._popoverHelper.hidePopover();
  1720. },
  1721.  
  1722. refresh: function()
  1723. {
  1724. this._needsRefresh = false;
  1725. if (this._refreshTimeout) {
  1726. clearTimeout(this._refreshTimeout);
  1727. delete this._refreshTimeout;
  1728. }
  1729.  
  1730. this._removeAllNodeHighlights();
  1731. var wasScrolledToLastRow = this._dataGrid.isScrolledToLastRow();
  1732. var boundariesChanged = false;
  1733. if (this.calculator.updateBoundariesForEventTime) {
  1734. boundariesChanged = this.calculator.updateBoundariesForEventTime(this._mainRequestLoadTime) || boundariesChanged;
  1735. boundariesChanged = this.calculator.updateBoundariesForEventTime(this._mainRequestDOMContentTime) || boundariesChanged;
  1736. }
  1737.  
  1738. for (var requestId in this._staleRequests) {
  1739. var request = this._staleRequests[requestId];
  1740. var node = this._requestGridNode(request);
  1741. if (node)
  1742. node.refreshRequest();
  1743. else {
  1744.  
  1745. node = this._createRequestGridNode(request);
  1746. this._dataGrid.rootNode().appendChild(node);
  1747. node.refreshRequest();
  1748. this._applyFilter(node);
  1749. }
  1750.  
  1751. if (this.calculator.updateBoundaries(request))
  1752. boundariesChanged = true;
  1753.  
  1754. if (!node.isFilteredOut())
  1755. this._updateHighlightIfMatched(request);
  1756. }
  1757.  
  1758. if (boundariesChanged) {
  1759.  
  1760. this._invalidateAllItems();
  1761. }
  1762.  
  1763. for (var requestId in this._staleRequests)
  1764. this._requestGridNode(this._staleRequests[requestId]).refreshGraph(this.calculator);
  1765.  
  1766. this._staleRequests = {};
  1767. this._sortItems();
  1768. this._updateSummaryBar();
  1769. this._dataGrid.updateWidths();
  1770.  
  1771. if (wasScrolledToLastRow)
  1772. this._dataGrid.scrollToLastRow();
  1773. },
  1774.  
  1775. _onPreserveLogClicked: function(e)
  1776. {
  1777. this._preserveLogToggle.toggled = !this._preserveLogToggle.toggled;
  1778. },
  1779.  
  1780. _reset: function()
  1781. {
  1782. this.dispatchEventToListeners(WebInspector.NetworkLogView.EventTypes.ViewCleared);
  1783.  
  1784. this._clearSearchMatchedList();
  1785. if (this._popoverHelper)
  1786. this._popoverHelper.hidePopover();
  1787.  
  1788. if (this._calculator)
  1789. this._calculator.reset();
  1790.  
  1791. this._requests = [];
  1792. this._requestsById = {};
  1793. this._requestsByURL = {};
  1794. this._staleRequests = {};
  1795. this._requestGridNodes = {};
  1796.  
  1797. if (this._dataGrid) {
  1798. this._dataGrid.rootNode().removeChildren();
  1799. this._updateDividersIfNeeded();
  1800. this._updateSummaryBar();
  1801. }
  1802.  
  1803. this._mainRequestLoadTime = -1;
  1804. this._mainRequestDOMContentTime = -1;
  1805. this._linkifier.reset();
  1806. },
  1807.  
  1808. get requests()
  1809. {
  1810. return this._requests;
  1811. },
  1812.  
  1813. requestById: function(id)
  1814. {
  1815. return this._requestsById[id];
  1816. },
  1817.  
  1818. _onRequestStarted: function(event)
  1819. {
  1820. this._appendRequest(event.data);
  1821. },
  1822.  
  1823. _appendRequest: function(request)
  1824. {
  1825. this._requests.push(request);
  1826.  
  1827.  
  1828.  
  1829. if (this._requestsById[request.requestId]) {
  1830. var oldRequest = request.redirects[request.redirects.length - 1];
  1831. this._requestsById[oldRequest.requestId] = oldRequest;
  1832.  
  1833. this._updateSearchMatchedListAfterRequestIdChanged(request.requestId, oldRequest.requestId);
  1834. }
  1835. this._requestsById[request.requestId] = request;
  1836.  
  1837. this._requestsByURL[request.url] = request;
  1838.  
  1839.  
  1840. if (request.redirects) {
  1841. for (var i = 0; i < request.redirects.length; ++i)
  1842. this._refreshRequest(request.redirects[i]);
  1843. }
  1844.  
  1845. this._refreshRequest(request);
  1846. },
  1847.  
  1848.  
  1849. _onRequestUpdated: function(event)
  1850. {
  1851. var request =   (event.data);
  1852. this._refreshRequest(request);
  1853. },
  1854.  
  1855.  
  1856. _refreshRequest: function(request)
  1857. {
  1858. this._staleRequests[request.requestId] = request;
  1859. this._scheduleRefresh();
  1860. },
  1861.  
  1862. clear: function()
  1863. {
  1864. if (this._preserveLogToggle.toggled)
  1865. return;
  1866. this._reset();
  1867. },
  1868.  
  1869. _mainFrameNavigated: function(event)
  1870. {
  1871. if (this._preserveLogToggle.toggled)
  1872. return;
  1873.  
  1874. var frame =   (event.data);
  1875. var loaderId = frame.loaderId;
  1876.  
  1877.  
  1878. var requestsToPreserve = [];
  1879. for (var i = 0; i < this._requests.length; ++i) {
  1880. var request = this._requests[i];
  1881. if (request.loaderId === loaderId)
  1882. requestsToPreserve.push(request);
  1883. }
  1884.  
  1885. this._reset();
  1886.  
  1887.  
  1888. for (var i = 0; i < requestsToPreserve.length; ++i)
  1889. this._appendRequest(requestsToPreserve[i]);
  1890. },
  1891.  
  1892. switchToDetailedView: function()
  1893. {
  1894. if (!this._dataGrid)
  1895. return;
  1896. if (this._dataGrid.selectedNode)
  1897. this._dataGrid.selectedNode.selected = false;
  1898.  
  1899. this.element.removeStyleClass("brief-mode");
  1900.  
  1901. this._dataGrid.showColumn("method");
  1902. this._dataGrid.showColumn("status");
  1903. this._dataGrid.showColumn("type");
  1904. this._dataGrid.showColumn("initiator");
  1905. this._dataGrid.showColumn("size");
  1906. this._dataGrid.showColumn("time");
  1907. this._dataGrid.showColumn("timeline");
  1908.  
  1909. var widths = {};
  1910. widths.name = 20;
  1911. widths.method = 6;
  1912. widths.status = 6;
  1913. widths.type = 6;
  1914. widths.initiator = 10;
  1915. widths.size = 6;
  1916. widths.time = 6;
  1917. widths.timeline = 40;
  1918.  
  1919. this._dataGrid.applyColumnWidthsMap(widths);
  1920. },
  1921.  
  1922. switchToBriefView: function()
  1923. {
  1924. this.element.addStyleClass("brief-mode");
  1925. this._removeAllNodeHighlights();
  1926.  
  1927. this._dataGrid.hideColumn("method");
  1928. this._dataGrid.hideColumn("status");
  1929. this._dataGrid.hideColumn("type");
  1930. this._dataGrid.hideColumn("initiator");
  1931. this._dataGrid.hideColumn("size");
  1932. this._dataGrid.hideColumn("time");
  1933. this._dataGrid.hideColumn("timeline");
  1934.  
  1935. var widths = {};
  1936. widths.name = 100;
  1937. this._dataGrid.applyColumnWidthsMap(widths);
  1938.  
  1939. this._popoverHelper.hidePopover();
  1940. },
  1941.  
  1942. _toggleLargerRequests: function()
  1943. {
  1944. WebInspector.settings.resourcesLargeRows.set(!WebInspector.settings.resourcesLargeRows.get());
  1945. this._setLargerRequests(WebInspector.settings.resourcesLargeRows.get());
  1946. },
  1947.  
  1948. _setLargerRequests: function(enabled)
  1949. {
  1950. this._largerRequestsButton.toggled = enabled;
  1951. if (!enabled) {
  1952. this._largerRequestsButton.title = WebInspector.UIString("Use large resource rows.");
  1953. this._dataGrid.element.addStyleClass("small");
  1954. this._timelineGrid.element.addStyleClass("small");
  1955. } else {
  1956. this._largerRequestsButton.title = WebInspector.UIString("Use small resource rows.");
  1957. this._dataGrid.element.removeStyleClass("small");
  1958. this._timelineGrid.element.removeStyleClass("small");
  1959. }
  1960. this.dispatchEventToListeners(WebInspector.NetworkLogView.EventTypes.RowSizeChanged, { largeRows: enabled });
  1961. this._updateOffscreenRows();
  1962. },
  1963.  
  1964. _getPopoverAnchor: function(element)
  1965. {
  1966. if (!this._allowPopover)
  1967. return;
  1968. var anchor = element.enclosingNodeOrSelfWithClass("network-graph-bar") || element.enclosingNodeOrSelfWithClass("network-graph-label");
  1969. if (!anchor)
  1970. return null;
  1971. var request = anchor.parentElement.request;
  1972. return request && request.timing ? anchor : null;
  1973. },
  1974.  
  1975.  
  1976. _showPopover: function(anchor, popover)
  1977. {
  1978. var request = anchor.parentElement.request;
  1979. var tableElement = WebInspector.RequestTimingView.createTimingTable(request);
  1980. popover.show(tableElement, anchor);
  1981. },
  1982.  
  1983. _contextMenu: function(event)
  1984. {
  1985. var contextMenu = new WebInspector.ContextMenu(event);
  1986. var gridNode = this._dataGrid.dataGridNodeFromNode(event.target);
  1987. var request = gridNode && gridNode._request;
  1988.  
  1989. if (request) {
  1990. contextMenu.appendItem(WebInspector.openLinkExternallyLabel(), WebInspector.openResource.bind(WebInspector, request.url, false));
  1991. contextMenu.appendSeparator();
  1992. contextMenu.appendItem(WebInspector.copyLinkAddressLabel(), this._copyLocation.bind(this, request));
  1993. if (request.requestHeadersText)
  1994. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Copy request headers" : "Copy Request Headers"), this._copyRequestHeaders.bind(this, request));
  1995. if (request.responseHeadersText)
  1996. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Copy response headers" : "Copy Response Headers"), this._copyResponseHeaders.bind(this, request));
  1997. }
  1998. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Copy all as HAR" : "Copy All as HAR"), this._copyAll.bind(this));
  1999.  
  2000. if (InspectorFrontendHost.canSave()) {
  2001. contextMenu.appendSeparator();
  2002. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Save as HAR with content" : "Save as HAR with Content"), this._exportAll.bind(this));
  2003. }
  2004.  
  2005. if (this._canClearBrowserCache || this._canClearBrowserCookies)
  2006. contextMenu.appendSeparator();
  2007. if (this._canClearBrowserCache)
  2008. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Clear browser cache" : "Clear Browser Cache"), this._clearBrowserCache.bind(this));
  2009. if (this._canClearBrowserCookies)
  2010. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Clear browser cookies" : "Clear Browser Cookies"), this._clearBrowserCookies.bind(this));
  2011.  
  2012.  
  2013. if (request && request.type === WebInspector.resourceTypes.XHR) {
  2014. contextMenu.appendSeparator();
  2015. contextMenu.appendItem(WebInspector.UIString("Replay XHR"), this._replayXHR.bind(this, request.requestId));
  2016. contextMenu.appendSeparator();
  2017. }
  2018.  
  2019. contextMenu.show();
  2020. },
  2021.  
  2022. _replayXHR: function(requestId)
  2023. {
  2024. NetworkAgent.replayXHR(requestId);
  2025. },
  2026.  
  2027.  
  2028. _copyAll: function()
  2029. {
  2030. var harArchive = {
  2031. log: (new WebInspector.HARLog(this._requests)).build()
  2032. };
  2033. InspectorFrontendHost.copyText(JSON.stringify(harArchive, null, 2));
  2034. },
  2035.  
  2036. _copyLocation: function(request)
  2037. {
  2038. InspectorFrontendHost.copyText(request.url);
  2039. },
  2040.  
  2041. _copyRequestHeaders: function(request)
  2042. {
  2043. InspectorFrontendHost.copyText(request.requestHeadersText);
  2044. },
  2045.  
  2046. _copyResponseHeaders: function(request)
  2047. {
  2048. InspectorFrontendHost.copyText(request.responseHeadersText);
  2049. },
  2050.  
  2051. _exportAll: function()
  2052. {
  2053. var filename = WebInspector.inspectedPageDomain + ".har";
  2054. var stream = new WebInspector.FileOutputStream();
  2055. stream.open(filename, openCallback.bind(this));
  2056. function openCallback()
  2057. {
  2058. var progressIndicator = new WebInspector.ProgressIndicator();
  2059. this._progressBarContainer.appendChild(progressIndicator.element);
  2060. var harWriter = new WebInspector.HARWriter();
  2061. harWriter.write(stream, this._requests, progressIndicator);
  2062. }
  2063. },
  2064.  
  2065. _clearBrowserCache: function(event)
  2066. {
  2067. if (confirm(WebInspector.UIString("Are you sure you want to clear browser cache?")))
  2068. NetworkAgent.clearBrowserCache();
  2069. },
  2070.  
  2071. _clearBrowserCookies: function(event)
  2072. {
  2073. if (confirm(WebInspector.UIString("Are you sure you want to clear browser cookies?")))
  2074. NetworkAgent.clearBrowserCookies();
  2075. },
  2076.  
  2077. _updateOffscreenRows: function()
  2078. {
  2079. var dataTableBody = this._dataGrid.dataTableBody;
  2080. var rows = dataTableBody.children;
  2081. var recordsCount = rows.length;
  2082. if (recordsCount < 2)
  2083. return;  
  2084.  
  2085. var visibleTop = this._dataGrid.scrollContainer.scrollTop;
  2086. var visibleBottom = visibleTop + this._dataGrid.scrollContainer.offsetHeight;
  2087.  
  2088. var rowHeight = 0;
  2089.  
  2090.  
  2091. var unfilteredRowIndex = 0;
  2092. for (var i = 0; i < recordsCount - 1; ++i) {
  2093. var row = rows[i];
  2094.  
  2095. var dataGridNode = this._dataGrid.dataGridNodeFromNode(row);
  2096. if (dataGridNode.isFilteredOut()) {
  2097. row.removeStyleClass("offscreen");
  2098. continue;
  2099. }
  2100.  
  2101. if (!rowHeight)
  2102. rowHeight = row.offsetHeight;
  2103.  
  2104. var rowIsVisible = unfilteredRowIndex * rowHeight < visibleBottom && (unfilteredRowIndex + 1) * rowHeight > visibleTop;
  2105. if (rowIsVisible !== row.rowIsVisible) {
  2106. if (rowIsVisible)
  2107. row.removeStyleClass("offscreen");
  2108. else
  2109. row.addStyleClass("offscreen");
  2110. row.rowIsVisible = rowIsVisible;
  2111. }
  2112. unfilteredRowIndex++;
  2113. }
  2114. },
  2115.  
  2116. _matchRequest: function(request)
  2117. {
  2118. if (!this._searchRegExp)
  2119. return -1;
  2120.  
  2121. if (!request.name().match(this._searchRegExp) && !request.path().match(this._searchRegExp))
  2122. return -1;
  2123.  
  2124. if (request.requestId in this._matchedRequestsMap)
  2125. return this._matchedRequestsMap[request.requestId];
  2126.  
  2127. var matchedRequestIndex = this._matchedRequests.length;
  2128. this._matchedRequestsMap[request.requestId] = matchedRequestIndex;
  2129. this._matchedRequests.push(request.requestId);
  2130.  
  2131. return matchedRequestIndex;
  2132. },
  2133.  
  2134. _clearSearchMatchedList: function()
  2135. {
  2136. delete this._searchRegExp;
  2137. this._matchedRequests = [];
  2138. this._matchedRequestsMap = {};
  2139. this._removeAllHighlights();
  2140. },
  2141.  
  2142. _updateSearchMatchedListAfterRequestIdChanged: function(oldRequestId, newRequestId)
  2143. {
  2144. var requestIndex = this._matchedRequestsMap[oldRequestId];
  2145. if (requestIndex) {
  2146. delete this._matchedRequestsMap[oldRequestId];
  2147. this._matchedRequestsMap[newRequestId] = requestIndex;
  2148. this._matchedRequests[requestIndex] = newRequestId;
  2149. }
  2150. },
  2151.  
  2152. _updateHighlightIfMatched: function(request)
  2153. {
  2154. var matchedRequestIndex = this._matchRequest(request);
  2155. if (matchedRequestIndex === -1)
  2156. return;
  2157.  
  2158. this.dispatchEventToListeners(WebInspector.NetworkLogView.EventTypes.SearchCountUpdated, this._matchedRequests.length);
  2159.  
  2160. if (this._currentMatchedRequestIndex !== -1 && this._currentMatchedRequestIndex !== matchedRequestIndex)
  2161. return;
  2162.  
  2163. this._highlightNthMatchedRequestForSearch(matchedRequestIndex, false);
  2164. },
  2165.  
  2166. _removeAllHighlights: function()
  2167. {
  2168. for (var i = 0; i < this._highlightedSubstringChanges.length; ++i)
  2169. WebInspector.revertDomChanges(this._highlightedSubstringChanges[i]);
  2170. this._highlightedSubstringChanges = [];
  2171. },
  2172.  
  2173.  
  2174. _highlightMatchedRequest: function(request, reveal, regExp)
  2175. {
  2176. var node = this._requestGridNode(request);
  2177. if (!node)
  2178. return;
  2179.  
  2180. var nameMatched = request.name().match(regExp);
  2181. var pathMatched = request.path().match(regExp);
  2182. if (!nameMatched && pathMatched && !this._largerRequestsButton.toggled)
  2183. this._toggleLargerRequests();
  2184. var highlightedSubstringChanges = node._highlightMatchedSubstring(regExp);
  2185. this._highlightedSubstringChanges.push(highlightedSubstringChanges);
  2186. if (reveal)
  2187. node.reveal();
  2188. },
  2189.  
  2190.  
  2191. _highlightNthMatchedRequestForSearch: function(matchedRequestIndex, reveal)
  2192. {
  2193. var request = this.requestById(this._matchedRequests[matchedRequestIndex]);
  2194. if (!request)
  2195. return;
  2196. this._removeAllHighlights();
  2197. this._highlightMatchedRequest(request, reveal, this._searchRegExp);
  2198. var node = this._requestGridNode(request);
  2199. if (node)
  2200. this._currentMatchedRequestIndex = matchedRequestIndex;
  2201.  
  2202. this.dispatchEventToListeners(WebInspector.NetworkLogView.EventTypes.SearchIndexUpdated, this._currentMatchedRequestIndex);
  2203. },
  2204.  
  2205. performSearch: function(searchQuery)
  2206. {
  2207. var newMatchedRequestIndex = 0;
  2208. var currentMatchedRequestId;
  2209. if (this._currentMatchedRequestIndex !== -1)
  2210. currentMatchedRequestId = this._matchedRequests[this._currentMatchedRequestIndex];
  2211.  
  2212. this._clearSearchMatchedList();
  2213. this._searchRegExp = createPlainTextSearchRegex(searchQuery, "i");
  2214.  
  2215. var childNodes = this._dataGrid.dataTableBody.childNodes;
  2216. var requestNodes = Array.prototype.slice.call(childNodes, 0, childNodes.length - 1); 
  2217.  
  2218. for (var i = 0; i < requestNodes.length; ++i) {
  2219. var dataGridNode = this._dataGrid.dataGridNodeFromNode(requestNodes[i]);
  2220. if (dataGridNode.isFilteredOut())
  2221. continue;
  2222. if (this._matchRequest(dataGridNode._request) !== -1 && dataGridNode._request.requestId === currentMatchedRequestId)
  2223. newMatchedRequestIndex = this._matchedRequests.length - 1;
  2224. }
  2225.  
  2226. this.dispatchEventToListeners(WebInspector.NetworkLogView.EventTypes.SearchCountUpdated, this._matchedRequests.length);
  2227. this._highlightNthMatchedRequestForSearch(newMatchedRequestIndex, false);
  2228. },
  2229.  
  2230.  
  2231. _applyFilter: function(node) {
  2232. var filter = this._filterRegExp;
  2233. var request = node._request;
  2234. if (!filter)
  2235. return;
  2236. if (filter.test(request.name()) || filter.test(request.path()))
  2237. this._highlightMatchedRequest(request, false, filter);
  2238. else {
  2239. node.element.addStyleClass("filtered-out");
  2240. this._filteredOutRequests.put(request, true);
  2241. }
  2242. },
  2243.  
  2244.  
  2245. performFilter: function(query)
  2246. {
  2247. this._removeAllHighlights();
  2248. this._filteredOutRequests.clear();
  2249. delete this._filterRegExp;
  2250. if (query)
  2251. this._filterRegExp = createPlainTextSearchRegex(query, "i");
  2252.  
  2253. var nodes = this._dataGrid.rootNode().children;
  2254. for (var i = 0; i < nodes.length; ++i) {
  2255. nodes[i].element.removeStyleClass("filtered-out");
  2256. this._applyFilter(nodes[i]);
  2257. }
  2258. this._updateSummaryBar();
  2259. this._updateOffscreenRows();
  2260. },
  2261.  
  2262. jumpToPreviousSearchResult: function()
  2263. {
  2264. if (!this._matchedRequests.length)
  2265. return;
  2266. this._highlightNthMatchedRequestForSearch((this._currentMatchedRequestIndex + this._matchedRequests.length - 1) % this._matchedRequests.length, true);
  2267. },
  2268.  
  2269. jumpToNextSearchResult: function()
  2270. {
  2271. if (!this._matchedRequests.length)
  2272. return;
  2273. this._highlightNthMatchedRequestForSearch((this._currentMatchedRequestIndex + 1) % this._matchedRequests.length, true);
  2274. },
  2275.  
  2276. searchCanceled: function()
  2277. {
  2278. this._clearSearchMatchedList();
  2279. this.dispatchEventToListeners(WebInspector.NetworkLogView.EventTypes.SearchCountUpdated, 0);
  2280. },
  2281.  
  2282. revealAndHighlightRequest: function(request)
  2283. {
  2284. this._removeAllNodeHighlights();
  2285.  
  2286. var node = this._requestGridNode(request);
  2287. if (node) {
  2288. this._dataGrid.element.focus();
  2289. node.reveal();
  2290. this._highlightNode(node);
  2291. }
  2292. },
  2293.  
  2294. _removeAllNodeHighlights: function()
  2295. {
  2296. if (this._highlightedNode) {
  2297. this._highlightedNode.element.removeStyleClass("highlighted-row");
  2298. delete this._highlightedNode;
  2299. }
  2300. },
  2301.  
  2302. _highlightNode: function(node)
  2303. {
  2304. node.element.addStyleClass("highlighted-row");
  2305. this._highlightedNode = node;
  2306. },
  2307.  
  2308. __proto__: WebInspector.View.prototype
  2309. }
  2310.  
  2311.  
  2312. WebInspector.NetworkLogView.EventTypes = {
  2313. ViewCleared: "ViewCleared",
  2314. RowSizeChanged: "RowSizeChanged",
  2315. RequestSelected: "RequestSelected",
  2316. SearchCountUpdated: "SearchCountUpdated",
  2317. SearchIndexUpdated: "SearchIndexUpdated"
  2318. };
  2319.  
  2320.  
  2321. WebInspector.NetworkPanel = function()
  2322. {
  2323. WebInspector.Panel.call(this, "network");
  2324. this.registerRequiredCSS("networkPanel.css");
  2325.  
  2326. this.createSidebarView();
  2327. this.splitView.hideMainElement();
  2328.  
  2329. this._networkLogView = new WebInspector.NetworkLogView();
  2330. this._networkLogView.show(this.sidebarElement);
  2331.  
  2332. this._viewsContainerElement = this.splitView.mainElement;
  2333. this._viewsContainerElement.id = "network-views";
  2334. this._viewsContainerElement.addStyleClass("hidden");
  2335. if (!this._networkLogView.useLargeRows)
  2336. this._viewsContainerElement.addStyleClass("small");
  2337.  
  2338. this._networkLogView.addEventListener(WebInspector.NetworkLogView.EventTypes.ViewCleared, this._onViewCleared, this);
  2339. this._networkLogView.addEventListener(WebInspector.NetworkLogView.EventTypes.RowSizeChanged, this._onRowSizeChanged, this);
  2340. this._networkLogView.addEventListener(WebInspector.NetworkLogView.EventTypes.RequestSelected, this._onRequestSelected, this);
  2341. this._networkLogView.addEventListener(WebInspector.NetworkLogView.EventTypes.SearchCountUpdated, this._onSearchCountUpdated, this);
  2342. this._networkLogView.addEventListener(WebInspector.NetworkLogView.EventTypes.SearchIndexUpdated, this._onSearchIndexUpdated, this);
  2343.  
  2344. this._closeButtonElement = document.createElement("button");
  2345. this._closeButtonElement.id = "network-close-button";
  2346. this._closeButtonElement.addEventListener("click", this._toggleGridMode.bind(this), false);
  2347. this._viewsContainerElement.appendChild(this._closeButtonElement);
  2348.  
  2349. function viewGetter()
  2350. {
  2351. return this.visibleView;
  2352. }
  2353. WebInspector.GoToLineDialog.install(this, viewGetter.bind(this));
  2354. }
  2355.  
  2356. WebInspector.NetworkPanel.prototype = {
  2357. get statusBarItems()
  2358. {
  2359. return this._networkLogView.statusBarItems;
  2360. },
  2361.  
  2362. elementsToRestoreScrollPositionsFor: function()
  2363. {
  2364. return this._networkLogView.elementsToRestoreScrollPositionsFor();
  2365. },
  2366.  
  2367.  
  2368. _reset: function()
  2369. {
  2370. this._networkLogView._reset();
  2371. },
  2372.  
  2373. handleShortcut: function(event)
  2374. {
  2375. if (this._viewingRequestMode && event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.code) {
  2376. this._toggleGridMode();
  2377. event.handled = true;
  2378. return;
  2379. }
  2380.  
  2381. WebInspector.Panel.prototype.handleShortcut.call(this, event);
  2382. },
  2383.  
  2384. wasShown: function()
  2385. {
  2386. WebInspector.Panel.prototype.wasShown.call(this);
  2387. },
  2388.  
  2389. get requests()
  2390. {
  2391. return this._networkLogView.requests;
  2392. },
  2393.  
  2394. requestById: function(id)
  2395. {
  2396. return this._networkLogView.requestById(id);
  2397. },
  2398.  
  2399. _requestByAnchor: function(anchor)
  2400. {
  2401. return anchor.requestId ? this.requestById(anchor.requestId) : this._networkLogView._requestsByURL[anchor.href];
  2402. },
  2403.  
  2404. canShowAnchorLocation: function(anchor)
  2405. {
  2406. return !!this._requestByAnchor(anchor);
  2407. },
  2408.  
  2409. showAnchorLocation: function(anchor)
  2410. {
  2411. var request = this._requestByAnchor(anchor);
  2412. this.revealAndHighlightRequest(request)
  2413. },
  2414.  
  2415. revealAndHighlightRequest: function(request)
  2416. {
  2417. this._toggleGridMode();
  2418. if (request)
  2419. this._networkLogView.revealAndHighlightRequest(request);
  2420. },
  2421.  
  2422. _onViewCleared: function(event)
  2423. {
  2424. this._closeVisibleRequest();
  2425. this._toggleGridMode();
  2426. this._viewsContainerElement.removeChildren();
  2427. this._viewsContainerElement.appendChild(this._closeButtonElement);
  2428. },
  2429.  
  2430. _onRowSizeChanged: function(event)
  2431. {
  2432. if (event.data.largeRows)
  2433. this._viewsContainerElement.removeStyleClass("small");
  2434. else
  2435. this._viewsContainerElement.addStyleClass("small");
  2436. },
  2437.  
  2438. _onSearchCountUpdated: function(event)
  2439. {
  2440. WebInspector.searchController.updateSearchMatchesCount(event.data, this);
  2441. },
  2442.  
  2443. _onSearchIndexUpdated: function(event)
  2444. {
  2445. WebInspector.searchController.updateCurrentMatchIndex(event.data, this);
  2446. },
  2447.  
  2448. _onRequestSelected: function(event)
  2449. {
  2450. this._showRequest(event.data);
  2451. },
  2452.  
  2453. _showRequest: function(request)
  2454. {
  2455. if (!request)
  2456. return;
  2457.  
  2458. this._toggleViewingRequestMode();
  2459.  
  2460. if (this.visibleView) {
  2461. this.visibleView.detach();
  2462. delete this.visibleView;
  2463. }
  2464.  
  2465. var view = new WebInspector.NetworkItemView(request);
  2466. view.show(this._viewsContainerElement);
  2467. this.visibleView = view;
  2468. },
  2469.  
  2470. _closeVisibleRequest: function()
  2471. {
  2472. this.element.removeStyleClass("viewing-resource");
  2473.  
  2474. if (this.visibleView) {
  2475. this.visibleView.detach();
  2476. delete this.visibleView;
  2477. }
  2478. },
  2479.  
  2480. _toggleGridMode: function()
  2481. {
  2482. if (this._viewingRequestMode) {
  2483. this._viewingRequestMode = false;
  2484. this.element.removeStyleClass("viewing-resource");
  2485. this.splitView.hideMainElement();
  2486. }
  2487.  
  2488. this._networkLogView.switchToDetailedView();
  2489. this._networkLogView.allowPopover = true;
  2490. this._networkLogView._allowRequestSelection = false;
  2491. },
  2492.  
  2493. _toggleViewingRequestMode: function()
  2494. {
  2495. if (this._viewingRequestMode)
  2496. return;
  2497. this._viewingRequestMode = true;
  2498.  
  2499. this.element.addStyleClass("viewing-resource");
  2500. this.splitView.showMainElement();
  2501. this._networkLogView.allowPopover = false;
  2502. this._networkLogView._allowRequestSelection = true;
  2503. this._networkLogView.switchToBriefView();
  2504. },
  2505.  
  2506.  
  2507. performSearch: function(searchQuery)
  2508. {
  2509. this._networkLogView.performSearch(searchQuery);
  2510. },
  2511.  
  2512.  
  2513. canFilter: function()
  2514. {
  2515. return true;
  2516. },
  2517.  
  2518.  
  2519. performFilter: function(query)
  2520. {
  2521. this._networkLogView.performFilter(query);
  2522. },
  2523.  
  2524. jumpToPreviousSearchResult: function()
  2525. {
  2526. this._networkLogView.jumpToPreviousSearchResult();
  2527. },
  2528.  
  2529. jumpToNextSearchResult: function()
  2530. {
  2531. this._networkLogView.jumpToNextSearchResult();
  2532. },
  2533.  
  2534. searchCanceled: function()
  2535. {
  2536. this._networkLogView.searchCanceled();
  2537. },
  2538.  
  2539.  
  2540. appendApplicableItems: function(event, contextMenu, target)
  2541. {
  2542. if (!(target instanceof WebInspector.NetworkRequest))
  2543. return;
  2544. if (this.visibleView && this.visibleView.isShowing() && this.visibleView.request() === target)
  2545. return;
  2546.  
  2547. function reveal()
  2548. {
  2549. WebInspector.inspectorView.setCurrentPanel(this);
  2550. this.revealAndHighlightRequest(  (target));
  2551. }
  2552. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Reveal in network panel" : "Reveal in Network Panel"), reveal.bind(this));
  2553. },
  2554.  
  2555. __proto__: WebInspector.Panel.prototype
  2556. }
  2557.  
  2558.  
  2559. WebInspector.NetworkBaseCalculator = function()
  2560. {
  2561. }
  2562.  
  2563. WebInspector.NetworkBaseCalculator.prototype = {
  2564. computePosition: function(time)
  2565. {
  2566. return (time - this._minimumBoundary) / this.boundarySpan() * this._workingArea;
  2567. },
  2568.  
  2569. computeBarGraphPercentages: function(item)
  2570. {
  2571. return {start: 0, middle: 0, end: (this._value(item) / this.boundarySpan()) * 100};
  2572. },
  2573.  
  2574. computeBarGraphLabels: function(item)
  2575. {
  2576. const label = this.formatTime(this._value(item));
  2577. return {left: label, right: label, tooltip: label};
  2578. },
  2579.  
  2580. boundarySpan: function()
  2581. {
  2582. return this._maximumBoundary - this._minimumBoundary;
  2583. },
  2584.  
  2585. updateBoundaries: function(item)
  2586. {
  2587. this._minimumBoundary = 0;
  2588.  
  2589. var value = this._value(item);
  2590. if (typeof this._maximumBoundary === "undefined" || value > this._maximumBoundary) {
  2591. this._maximumBoundary = value;
  2592. return true;
  2593. }
  2594. return false;
  2595. },
  2596.  
  2597. reset: function()
  2598. {
  2599. delete this._minimumBoundary;
  2600. delete this._maximumBoundary;
  2601. },
  2602.  
  2603. maximumBoundary: function()
  2604. {
  2605. return this._maximumBoundary;
  2606. },
  2607.  
  2608. minimumBoundary: function()
  2609. {
  2610. return this._minimumBoundary;
  2611. },
  2612.  
  2613. _value: function(item)
  2614. {
  2615. return 0;
  2616. },
  2617.  
  2618. formatTime: function(value)
  2619. {
  2620. return value.toString();
  2621. },
  2622.  
  2623. setDisplayWindow: function(clientWidth)
  2624. {
  2625. this._workingArea = clientWidth;
  2626. this.paddingLeft = 0;
  2627. }
  2628. }
  2629.  
  2630.  
  2631. WebInspector.NetworkTimeCalculator = function(startAtZero)
  2632. {
  2633. WebInspector.NetworkBaseCalculator.call(this);
  2634. this.startAtZero = startAtZero;
  2635. }
  2636.  
  2637. WebInspector.NetworkTimeCalculator.prototype = {
  2638. computeBarGraphPercentages: function(request)
  2639. {
  2640. if (request.startTime !== -1)
  2641. var start = ((request.startTime - this._minimumBoundary) / this.boundarySpan()) * 100;
  2642. else
  2643. var start = 0;
  2644.  
  2645. if (request.responseReceivedTime !== -1)
  2646. var middle = ((request.responseReceivedTime - this._minimumBoundary) / this.boundarySpan()) * 100;
  2647. else
  2648. var middle = (this.startAtZero ? start : 100);
  2649.  
  2650. if (request.endTime !== -1)
  2651. var end = ((request.endTime - this._minimumBoundary) / this.boundarySpan()) * 100;
  2652. else
  2653. var end = (this.startAtZero ? middle : 100);
  2654.  
  2655. if (this.startAtZero) {
  2656. end -= start;
  2657. middle -= start;
  2658. start = 0;
  2659. }
  2660.  
  2661. return {start: start, middle: middle, end: end};
  2662. },
  2663.  
  2664. computePercentageFromEventTime: function(eventTime)
  2665. {
  2666.  
  2667.  
  2668.  
  2669. if (eventTime !== -1 && !this.startAtZero)
  2670. return ((eventTime - this._minimumBoundary) / this.boundarySpan()) * 100;
  2671.  
  2672. return 0;
  2673. },
  2674.  
  2675. updateBoundariesForEventTime: function(eventTime)
  2676. {
  2677. if (eventTime === -1 || this.startAtZero)
  2678. return false;
  2679.  
  2680. if (typeof this._maximumBoundary === "undefined" || eventTime > this._maximumBoundary) {
  2681. this._maximumBoundary = eventTime;
  2682. return true;
  2683. }
  2684. return false;
  2685. },
  2686.  
  2687. computeBarGraphLabels: function(request)
  2688. {
  2689. var rightLabel = "";
  2690. if (request.responseReceivedTime !== -1 && request.endTime !== -1)
  2691. rightLabel = this.formatTime(request.endTime - request.responseReceivedTime);
  2692.  
  2693. var hasLatency = request.latency > 0;
  2694. if (hasLatency)
  2695. var leftLabel = this.formatTime(request.latency);
  2696. else
  2697. var leftLabel = rightLabel;
  2698.  
  2699. if (request.timing)
  2700. return {left: leftLabel, right: rightLabel};
  2701.  
  2702. if (hasLatency && rightLabel) {
  2703. var total = this.formatTime(request.duration);
  2704. var tooltip = WebInspector.UIString("%s latency, %s download (%s total)", leftLabel, rightLabel, total);
  2705. } else if (hasLatency)
  2706. var tooltip = WebInspector.UIString("%s latency", leftLabel);
  2707. else if (rightLabel)
  2708. var tooltip = WebInspector.UIString("%s download", rightLabel);
  2709.  
  2710. if (request.cached)
  2711. tooltip = WebInspector.UIString("%s (from cache)", tooltip);
  2712. return {left: leftLabel, right: rightLabel, tooltip: tooltip};
  2713. },
  2714.  
  2715. updateBoundaries: function(request)
  2716. {
  2717. var didChange = false;
  2718.  
  2719. var lowerBound;
  2720. if (this.startAtZero)
  2721. lowerBound = 0;
  2722. else
  2723. lowerBound = this._lowerBound(request);
  2724.  
  2725. if (lowerBound !== -1 && (typeof this._minimumBoundary === "undefined" || lowerBound < this._minimumBoundary)) {
  2726. this._minimumBoundary = lowerBound;
  2727. didChange = true;
  2728. }
  2729.  
  2730. var upperBound = this._upperBound(request);
  2731. if (upperBound !== -1 && (typeof this._maximumBoundary === "undefined" || upperBound > this._maximumBoundary)) {
  2732. this._maximumBoundary = upperBound;
  2733. didChange = true;
  2734. }
  2735.  
  2736. return didChange;
  2737. },
  2738.  
  2739. formatTime: function(value)
  2740. {
  2741. return Number.secondsToString(value);
  2742. },
  2743.  
  2744. _lowerBound: function(request)
  2745. {
  2746. return 0;
  2747. },
  2748.  
  2749. _upperBound: function(request)
  2750. {
  2751. return 0;
  2752. },
  2753.  
  2754. __proto__: WebInspector.NetworkBaseCalculator.prototype
  2755. }
  2756.  
  2757.  
  2758. WebInspector.NetworkTransferTimeCalculator = function()
  2759. {
  2760. WebInspector.NetworkTimeCalculator.call(this, false);
  2761. }
  2762.  
  2763. WebInspector.NetworkTransferTimeCalculator.prototype = {
  2764. formatTime: function(value)
  2765. {
  2766. return Number.secondsToString(value);
  2767. },
  2768.  
  2769. _lowerBound: function(request)
  2770. {
  2771. return request.startTime;
  2772. },
  2773.  
  2774. _upperBound: function(request)
  2775. {
  2776. return request.endTime;
  2777. },
  2778.  
  2779. __proto__: WebInspector.NetworkTimeCalculator.prototype
  2780. }
  2781.  
  2782.  
  2783. WebInspector.NetworkTransferDurationCalculator = function()
  2784. {
  2785. WebInspector.NetworkTimeCalculator.call(this, true);
  2786. }
  2787.  
  2788. WebInspector.NetworkTransferDurationCalculator.prototype = {
  2789. formatTime: function(value)
  2790. {
  2791. return Number.secondsToString(value);
  2792. },
  2793.  
  2794. _upperBound: function(request)
  2795. {
  2796. return request.duration;
  2797. },
  2798.  
  2799. __proto__: WebInspector.NetworkTimeCalculator.prototype
  2800. }
  2801.  
  2802.  
  2803. WebInspector.NetworkDataGridNode = function(parentView, request)
  2804. {
  2805. WebInspector.DataGridNode.call(this, {});
  2806. this._parentView = parentView;
  2807. this._request = request;
  2808. }
  2809.  
  2810. WebInspector.NetworkDataGridNode.prototype = {
  2811. createCells: function()
  2812. {
  2813.  
  2814. this._element.addStyleClass("offscreen");
  2815. this._nameCell = this._createDivInTD("name");
  2816. this._methodCell = this._createDivInTD("method");
  2817. this._statusCell = this._createDivInTD("status");
  2818. this._typeCell = this._createDivInTD("type");
  2819. this._initiatorCell = this._createDivInTD("initiator");
  2820. this._sizeCell = this._createDivInTD("size");
  2821. this._timeCell = this._createDivInTD("time");
  2822. this._createTimelineCell();
  2823. this._nameCell.addEventListener("click", this.select.bind(this), false);
  2824. this._nameCell.addEventListener("dblclick", this._openInNewTab.bind(this), false);
  2825. },
  2826.  
  2827. isFilteredOut: function()
  2828. {
  2829. if (this._parentView._filteredOutRequests.get(this._request))
  2830. return true;
  2831. if (!this._parentView._hiddenCategories.all)
  2832. return false;
  2833. return this._request.type.name() in this._parentView._hiddenCategories;
  2834. },
  2835.  
  2836. select: function()
  2837. {
  2838. this._parentView.dispatchEventToListeners(WebInspector.NetworkLogView.EventTypes.RequestSelected, this._request);
  2839. WebInspector.DataGridNode.prototype.select.apply(this, arguments);
  2840.  
  2841. WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMetrics.UserAction, {
  2842. action: WebInspector.UserMetrics.UserActionNames.NetworkRequestSelected,
  2843. url: this._request.url
  2844. });
  2845. },
  2846.  
  2847. _highlightMatchedSubstring: function(regexp)
  2848. {
  2849. var domChanges = [];
  2850. var matchInfo = this._element.textContent.match(regexp);
  2851. if (matchInfo)
  2852. WebInspector.highlightSearchResult(this._nameCell, matchInfo.index, matchInfo[0].length, domChanges);
  2853. return domChanges;
  2854. },
  2855.  
  2856. _openInNewTab: function()
  2857. {
  2858. InspectorFrontendHost.openInNewTab(this._request.url);
  2859. },
  2860.  
  2861. get selectable()
  2862. {
  2863. return this._parentView._allowRequestSelection && !this.isFilteredOut();
  2864. },
  2865.  
  2866. _createDivInTD: function(columnIdentifier)
  2867. {
  2868. var td = document.createElement("td");
  2869. td.className = columnIdentifier + "-column";
  2870. var div = document.createElement("div");
  2871. td.appendChild(div);
  2872. this._element.appendChild(td);
  2873. return div;
  2874. },
  2875.  
  2876. _createTimelineCell: function()
  2877. {
  2878. this._graphElement = document.createElement("div");
  2879. this._graphElement.className = "network-graph-side";
  2880.  
  2881. this._barAreaElement = document.createElement("div");
  2882.  
  2883. this._barAreaElement.className = "network-graph-bar-area";
  2884. this._barAreaElement.request = this._request;
  2885. this._graphElement.appendChild(this._barAreaElement);
  2886.  
  2887. this._barLeftElement = document.createElement("div");
  2888. this._barLeftElement.className = "network-graph-bar waiting";
  2889. this._barAreaElement.appendChild(this._barLeftElement);
  2890.  
  2891. this._barRightElement = document.createElement("div");
  2892. this._barRightElement.className = "network-graph-bar";
  2893. this._barAreaElement.appendChild(this._barRightElement);
  2894.  
  2895.  
  2896. this._labelLeftElement = document.createElement("div");
  2897. this._labelLeftElement.className = "network-graph-label waiting";
  2898. this._barAreaElement.appendChild(this._labelLeftElement);
  2899.  
  2900. this._labelRightElement = document.createElement("div");
  2901. this._labelRightElement.className = "network-graph-label";
  2902. this._barAreaElement.appendChild(this._labelRightElement);
  2903.  
  2904. this._graphElement.addEventListener("mouseover", this._refreshLabelPositions.bind(this), false);
  2905.  
  2906. this._timelineCell = document.createElement("td");
  2907. this._timelineCell.className = "timeline-column";
  2908. this._element.appendChild(this._timelineCell);
  2909. this._timelineCell.appendChild(this._graphElement);
  2910. },
  2911.  
  2912. refreshRequest: function()
  2913. {
  2914. this._refreshNameCell();
  2915.  
  2916. this._methodCell.setTextAndTitle(this._request.requestMethod);
  2917.  
  2918. this._refreshStatusCell();
  2919. this._refreshTypeCell();
  2920. this._refreshInitiatorCell();
  2921. this._refreshSizeCell();
  2922. this._refreshTimeCell();
  2923.  
  2924. if (this._request.cached)
  2925. this._graphElement.addStyleClass("resource-cached");
  2926.  
  2927. this._element.addStyleClass("network-item");
  2928. if (!this._element.hasStyleClass("network-type-" + this._request.type.name())) {
  2929. this._element.removeMatchingStyleClasses("network-type-\\w+");
  2930. this._element.addStyleClass("network-type-" + this._request.type.name());
  2931. }
  2932. },
  2933.  
  2934. _refreshNameCell: function()
  2935. {
  2936. this._nameCell.removeChildren();
  2937.  
  2938. if (this._request.type === WebInspector.resourceTypes.Image) {
  2939. var previewImage = document.createElement("img");
  2940. previewImage.className = "image-network-icon-preview";
  2941. this._request.populateImageSource(previewImage);
  2942.  
  2943. var iconElement = document.createElement("div");
  2944. iconElement.className = "icon";
  2945. iconElement.appendChild(previewImage);
  2946. } else {
  2947. var iconElement = document.createElement("img");
  2948. iconElement.className = "icon";
  2949. }
  2950. this._nameCell.appendChild(iconElement);
  2951. this._nameCell.appendChild(document.createTextNode(this._request.name()));
  2952. this._appendSubtitle(this._nameCell, this._request.path());
  2953. this._nameCell.title = this._request.url;
  2954. },
  2955.  
  2956. _refreshStatusCell: function()
  2957. {
  2958. this._statusCell.removeChildren();
  2959.  
  2960. if (this._request.failed) {
  2961. var failText = this._request.canceled ? WebInspector.UIString("(canceled)") : WebInspector.UIString("(failed)");
  2962. if (this._request.localizedFailDescription) {
  2963. this._statusCell.appendChild(document.createTextNode(failText));
  2964. this._appendSubtitle(this._statusCell, this._request.localizedFailDescription);
  2965. this._statusCell.title = failText + " " + this._request.localizedFailDescription;
  2966. } else {
  2967. this._statusCell.setTextAndTitle(failText);
  2968. }
  2969. this._statusCell.addStyleClass("network-dim-cell");
  2970. this.element.addStyleClass("network-error-row");
  2971. return;
  2972. }
  2973.  
  2974. this._statusCell.removeStyleClass("network-dim-cell");
  2975. this.element.removeStyleClass("network-error-row");
  2976.  
  2977. if (this._request.statusCode) {
  2978. this._statusCell.appendChild(document.createTextNode(this._request.statusCode));
  2979. this._appendSubtitle(this._statusCell, this._request.statusText);
  2980. this._statusCell.title = this._request.statusCode + " " + this._request.statusText;
  2981. if (this._request.statusCode >= 400)
  2982. this.element.addStyleClass("network-error-row");
  2983. if (this._request.cached)
  2984. this._statusCell.addStyleClass("network-dim-cell");
  2985. } else {
  2986. if (!this._request.isHttpFamily() && this._request.finished)
  2987. this._statusCell.setTextAndTitle(WebInspector.UIString("Success"));
  2988. else if (this._request.isPingRequest())
  2989. this._statusCell.setTextAndTitle(WebInspector.UIString("(ping)"));
  2990. else
  2991. this._statusCell.setTextAndTitle(WebInspector.UIString("(pending)"));
  2992. this._statusCell.addStyleClass("network-dim-cell");
  2993. }
  2994. },
  2995.  
  2996. _refreshTypeCell: function()
  2997. {
  2998. if (this._request.mimeType) {
  2999. this._typeCell.removeStyleClass("network-dim-cell");
  3000. this._typeCell.setTextAndTitle(this._request.mimeType);
  3001. } else if (this._request.isPingRequest()) {
  3002. this._typeCell.removeStyleClass("network-dim-cell");
  3003. this._typeCell.setTextAndTitle(this._request.requestContentType());
  3004. } else {
  3005. this._typeCell.addStyleClass("network-dim-cell");
  3006. this._typeCell.setTextAndTitle(WebInspector.UIString("Pending"));
  3007. }
  3008. },
  3009.  
  3010. _refreshInitiatorCell: function()
  3011. {
  3012. var initiator = this._request.initiator;
  3013. if ((initiator && initiator.type !== "other") || this._request.redirectSource) {
  3014. this._initiatorCell.removeStyleClass("network-dim-cell");
  3015. this._initiatorCell.removeChildren();
  3016. if (this._request.redirectSource) {
  3017. var redirectSource = this._request.redirectSource;
  3018. this._initiatorCell.title = redirectSource.url;
  3019. this._initiatorCell.appendChild(WebInspector.linkifyRequestAsNode(redirectSource));
  3020. this._appendSubtitle(this._initiatorCell, WebInspector.UIString("Redirect"));
  3021. } else if (initiator.type === "script") {
  3022. var topFrame = initiator.stackTrace[0];
  3023.  
  3024. if (!topFrame.url) {
  3025. this._initiatorCell.addStyleClass("network-dim-cell");
  3026. this._initiatorCell.setTextAndTitle(WebInspector.UIString("Other"));
  3027. return;
  3028. }
  3029. this._initiatorCell.title = topFrame.url + ":" + topFrame.lineNumber;
  3030. var urlElement = this._parentView._linkifier.linkifyLocation(topFrame.url, topFrame.lineNumber - 1, 0);
  3031. this._initiatorCell.appendChild(urlElement);
  3032. this._appendSubtitle(this._initiatorCell, WebInspector.UIString("Script"));
  3033. } else { 
  3034. this._initiatorCell.title = initiator.url + ":" + initiator.lineNumber;
  3035. this._initiatorCell.appendChild(WebInspector.linkifyResourceAsNode(initiator.url, initiator.lineNumber - 1));
  3036. this._appendSubtitle(this._initiatorCell, WebInspector.UIString("Parser"));
  3037. }
  3038. } else {
  3039. this._initiatorCell.addStyleClass("network-dim-cell");
  3040. this._initiatorCell.setTextAndTitle(WebInspector.UIString("Other"));
  3041. }
  3042. },
  3043.  
  3044. _refreshSizeCell: function()
  3045. {
  3046. if (this._request.cached) {
  3047. this._sizeCell.setTextAndTitle(WebInspector.UIString("(from cache)"));
  3048. this._sizeCell.addStyleClass("network-dim-cell");
  3049. } else {
  3050. var resourceSize = typeof this._request.resourceSize === "number" ? Number.bytesToString(this._request.resourceSize) : "?";
  3051. var transferSize = typeof this._request.transferSize === "number" ? Number.bytesToString(this._request.transferSize) : "?";
  3052. this._sizeCell.setTextAndTitle(transferSize);
  3053. this._sizeCell.removeStyleClass("network-dim-cell");
  3054. this._appendSubtitle(this._sizeCell, resourceSize);
  3055. }
  3056. },
  3057.  
  3058. _refreshTimeCell: function()
  3059. {
  3060. if (this._request.duration > 0) {
  3061. this._timeCell.removeStyleClass("network-dim-cell");
  3062. this._timeCell.setTextAndTitle(Number.secondsToString(this._request.duration));
  3063. this._appendSubtitle(this._timeCell, Number.secondsToString(this._request.latency));
  3064. } else {
  3065. this._timeCell.addStyleClass("network-dim-cell");
  3066. this._timeCell.setTextAndTitle(WebInspector.UIString("Pending"));
  3067. }
  3068. },
  3069.  
  3070. _appendSubtitle: function(cellElement, subtitleText)
  3071. {
  3072. var subtitleElement = document.createElement("div");
  3073. subtitleElement.className = "network-cell-subtitle";
  3074. subtitleElement.textContent = subtitleText;
  3075. cellElement.appendChild(subtitleElement);
  3076. },
  3077.  
  3078. refreshGraph: function(calculator)
  3079. {
  3080. var percentages = calculator.computeBarGraphPercentages(this._request);
  3081. this._percentages = percentages;
  3082.  
  3083. this._barAreaElement.removeStyleClass("hidden");
  3084.  
  3085. if (!this._graphElement.hasStyleClass("network-type-" + this._request.type.name())) {
  3086. this._graphElement.removeMatchingStyleClasses("network-type-\\w+");
  3087. this._graphElement.addStyleClass("network-type-" + this._request.type.name());
  3088. }
  3089.  
  3090. this._barLeftElement.style.setProperty("left", percentages.start + "%");
  3091. this._barRightElement.style.setProperty("right", (100 - percentages.end) + "%");
  3092.  
  3093. this._barLeftElement.style.setProperty("right", (100 - percentages.end) + "%");
  3094. this._barRightElement.style.setProperty("left", percentages.middle + "%");
  3095.  
  3096. var labels = calculator.computeBarGraphLabels(this._request);
  3097. this._labelLeftElement.textContent = labels.left;
  3098. this._labelRightElement.textContent = labels.right;
  3099.  
  3100. var tooltip = (labels.tooltip || "");
  3101. this._barLeftElement.title = tooltip;
  3102. this._labelLeftElement.title = tooltip;
  3103. this._labelRightElement.title = tooltip;
  3104. this._barRightElement.title = tooltip;
  3105. },
  3106.  
  3107. _refreshLabelPositions: function()
  3108. {
  3109. if (!this._percentages)
  3110. return;
  3111. this._labelLeftElement.style.removeProperty("left");
  3112. this._labelLeftElement.style.removeProperty("right");
  3113. this._labelLeftElement.removeStyleClass("before");
  3114. this._labelLeftElement.removeStyleClass("hidden");
  3115.  
  3116. this._labelRightElement.style.removeProperty("left");
  3117. this._labelRightElement.style.removeProperty("right");
  3118. this._labelRightElement.removeStyleClass("after");
  3119. this._labelRightElement.removeStyleClass("hidden");
  3120.  
  3121. const labelPadding = 10;
  3122. const barRightElementOffsetWidth = this._barRightElement.offsetWidth;
  3123. const barLeftElementOffsetWidth = this._barLeftElement.offsetWidth;
  3124.  
  3125. if (this._barLeftElement) {
  3126. var leftBarWidth = barLeftElementOffsetWidth - labelPadding;
  3127. var rightBarWidth = (barRightElementOffsetWidth - barLeftElementOffsetWidth) - labelPadding;
  3128. } else {
  3129. var leftBarWidth = (barLeftElementOffsetWidth - barRightElementOffsetWidth) - labelPadding;
  3130. var rightBarWidth = barRightElementOffsetWidth - labelPadding;
  3131. }
  3132.  
  3133. const labelLeftElementOffsetWidth = this._labelLeftElement.offsetWidth;
  3134. const labelRightElementOffsetWidth = this._labelRightElement.offsetWidth;
  3135.  
  3136. const labelBefore = (labelLeftElementOffsetWidth > leftBarWidth);
  3137. const labelAfter = (labelRightElementOffsetWidth > rightBarWidth);
  3138. const graphElementOffsetWidth = this._graphElement.offsetWidth;
  3139.  
  3140. if (labelBefore && (graphElementOffsetWidth * (this._percentages.start / 100)) < (labelLeftElementOffsetWidth + 10))
  3141. var leftHidden = true;
  3142.  
  3143. if (labelAfter && (graphElementOffsetWidth * ((100 - this._percentages.end) / 100)) < (labelRightElementOffsetWidth + 10))
  3144. var rightHidden = true;
  3145.  
  3146. if (barLeftElementOffsetWidth == barRightElementOffsetWidth) {
  3147.  
  3148. if (labelBefore && !labelAfter)
  3149. leftHidden = true;
  3150. else if (labelAfter && !labelBefore)
  3151. rightHidden = true;
  3152. }
  3153.  
  3154. if (labelBefore) {
  3155. if (leftHidden)
  3156. this._labelLeftElement.addStyleClass("hidden");
  3157. this._labelLeftElement.style.setProperty("right", (100 - this._percentages.start) + "%");
  3158. this._labelLeftElement.addStyleClass("before");
  3159. } else {
  3160. this._labelLeftElement.style.setProperty("left", this._percentages.start + "%");
  3161. this._labelLeftElement.style.setProperty("right", (100 - this._percentages.middle) + "%");
  3162. }
  3163.  
  3164. if (labelAfter) {
  3165. if (rightHidden)
  3166. this._labelRightElement.addStyleClass("hidden");
  3167. this._labelRightElement.style.setProperty("left", this._percentages.end + "%");
  3168. this._labelRightElement.addStyleClass("after");
  3169. } else {
  3170. this._labelRightElement.style.setProperty("left", this._percentages.middle + "%");
  3171. this._labelRightElement.style.setProperty("right", (100 - this._percentages.end) + "%");
  3172. }
  3173. },
  3174.  
  3175. __proto__: WebInspector.DataGridNode.prototype
  3176. }
  3177.  
  3178.  
  3179. WebInspector.NetworkDataGridNode.NameComparator = function(a, b)
  3180. {
  3181. var aFileName = a._request.name();
  3182. var bFileName = b._request.name();
  3183. if (aFileName > bFileName)
  3184. return 1;
  3185. if (bFileName > aFileName)
  3186. return -1;
  3187. return 0;
  3188. }
  3189.  
  3190. WebInspector.NetworkDataGridNode.SizeComparator = function(a, b)
  3191. {
  3192. if (b._request.cached && !a._request.cached)
  3193. return 1;
  3194. if (a._request.cached && !b._request.cached)
  3195. return -1;
  3196.  
  3197. if (a._request.resourceSize === b._request.resourceSize)
  3198. return 0;
  3199.  
  3200. return a._request.resourceSize - b._request.resourceSize;
  3201. }
  3202.  
  3203. WebInspector.NetworkDataGridNode.InitiatorComparator = function(a, b)
  3204. {
  3205. if (!a._request.initiator || a._request.initiator.type === "Other")
  3206. return -1;
  3207. if (!b._request.initiator || b._request.initiator.type === "Other")
  3208. return 1;
  3209.  
  3210. if (a._request.initiator.url < b._request.initiator.url)
  3211. return -1;
  3212. if (a._request.initiator.url > b._request.initiator.url)
  3213. return 1;
  3214.  
  3215. return a._request.initiator.lineNumber - b._request.initiator.lineNumber;
  3216. }
  3217.  
  3218. WebInspector.NetworkDataGridNode.RequestPropertyComparator = function(propertyName, revert, a, b)
  3219. {
  3220. var aValue = a._request[propertyName];
  3221. var bValue = b._request[propertyName];
  3222. if (aValue > bValue)
  3223. return revert ? -1 : 1;
  3224. if (bValue > aValue)
  3225. return revert ? 1 : -1;
  3226. return 0;
  3227. }
  3228.